| 6 | ) |
| 7 | |
| 8 | func TestGetTime(t *testing.T) { |
| 9 | now := time.Now() |
| 10 | tt := map[string]struct { |
| 11 | input func() *time.Time |
| 12 | expectedTime int64 |
| 13 | }{ |
| 14 | "it should return the current time": { |
| 15 | input: func() *time.Time { |
| 16 | return nil |
| 17 | }, |
| 18 | expectedTime: now.Unix(), |
| 19 | }, |
| 20 | "it should return the provided time": { |
| 21 | input: func() *time.Time { |
| 22 | parsed, err := time.Parse(time.RFC3339, "2024-10-15T09:32:23Z") |
| 23 | if err != nil { |
| 24 | t.Errorf("timeParse unexpected error: %v", err) |
| 25 | } |
| 26 | return &parsed |
| 27 | }, |
| 28 | expectedTime: 1728984743, |
| 29 | }, |
| 30 | } |
| 31 | |
| 32 | for name, tc := range tt { |
| 33 | t.Run(name, func(t *testing.T) { |
| 34 | result, _, err := getTime(tc.input()) |
| 35 | if err != nil { |
| 36 | t.Errorf("getTime unexpected error: %v", err) |
| 37 | } |
| 38 | sec, _ := result.UnixTime() |
| 39 | if sec != tc.expectedTime { |
| 40 | t.Errorf("expected %v, got %v", tc.expectedTime, result) |
| 41 | } |
| 42 | }) |
| 43 | } |
| 44 | } |