(t *testing.T)
| 6 | ) |
| 7 | |
| 8 | func TestNewV6WithTime(t *testing.T) { |
| 9 | testCases := map[string]string{ |
| 10 | "test with current date": time.Now().Format(time.RFC3339), // now |
| 11 | "test with past date": time.Now().Add(-1 * time.Hour * 24 * 365).Format(time.RFC3339), // 1 year ago |
| 12 | "test with future date": time.Now().Add(time.Hour * 24 * 365).Format(time.RFC3339), // 1 year from now |
| 13 | "test with different timezone": "2021-09-01T12:00:00+04:00", |
| 14 | "test with negative timezone": "2021-09-01T12:00:00-12:00", |
| 15 | "test with future date in different timezone": "2124-09-23T12:43:30+09:00", |
| 16 | } |
| 17 | |
| 18 | for testName, inputTime := range testCases { |
| 19 | t.Run(testName, func(t *testing.T) { |
| 20 | customTime, err := time.Parse(time.RFC3339, inputTime) |
| 21 | if err != nil { |
| 22 | t.Errorf("time.Parse returned unexpected error %v", err) |
| 23 | } |
| 24 | id, err := NewV6WithTime(&customTime) |
| 25 | if err != nil { |
| 26 | t.Errorf("NewV6WithTime returned unexpected error %v", err) |
| 27 | } |
| 28 | |
| 29 | if id.Version() != 6 { |
| 30 | t.Errorf("got %d, want version 6", id.Version()) |
| 31 | } |
| 32 | unixTime := time.Unix(id.Time().UnixTime()) |
| 33 | // Compare the times in UTC format, since the input time might have different timezone, |
| 34 | // and the result is always in system timezone |
| 35 | if customTime.UTC().Format(time.RFC3339) != unixTime.UTC().Format(time.RFC3339) { |
| 36 | t.Errorf("got %s, want %s", unixTime.Format(time.RFC3339), customTime.Format(time.RFC3339)) |
| 37 | } |
| 38 | }) |
| 39 | } |
| 40 | } |
| 41 | |
| 42 | func TestNewV6FromTimeGeneratesUniqueUUIDs(t *testing.T) { |
| 43 | now := time.Now() |
nothing calls this directly
no test coverage detected