MCPcopy
hub / github.com/google/uuid / TestNewV6WithTime

Function TestNewV6WithTime

version6_test.go:8–40  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

6)
7
8func 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
42func TestNewV6FromTimeGeneratesUniqueUUIDs(t *testing.T) {
43 now := time.Now()

Callers

nothing calls this directly

Calls 4

NewV6WithTimeFunction · 0.85
VersionMethod · 0.80
UnixTimeMethod · 0.80
TimeMethod · 0.80

Tested by

no test coverage detected