1
0
mirror of https://github.com/google/uuid.git synced 2024-11-21 17:16:42 +02:00
uuid/time_test.go
Nicu Micle 2d3c2a9cc5
feat: Generate V6 from custom time (#172)
* Add NewV6WithTime

* Refactor generateV6

* fix NewV6WithTime doc comment

* fix: remove fmt.Println from test

---------

Co-authored-by: nicumicle <20170987+nicumicleI@users.noreply.github.com>
2024-11-14 11:04:50 -06:00

45 lines
906 B
Go

package uuid
import (
"testing"
"time"
)
func TestGetTime(t *testing.T) {
now := time.Now()
tt := map[string]struct {
input func() *time.Time
expectedTime int64
}{
"it should return the current time": {
input: func() *time.Time {
return nil
},
expectedTime: now.Unix(),
},
"it should return the provided time": {
input: func() *time.Time {
parsed, err := time.Parse(time.RFC3339, "2024-10-15T09:32:23Z")
if err != nil {
t.Errorf("timeParse unexpected error: %v", err)
}
return &parsed
},
expectedTime: 1728984743,
},
}
for name, tc := range tt {
t.Run(name, func(t *testing.T) {
result, _, err := getTime(tc.input())
if err != nil {
t.Errorf("getTime unexpected error: %v", err)
}
sec, _ := result.UnixTime()
if sec != tc.expectedTime {
t.Errorf("expected %v, got %v", tc.expectedTime, result)
}
})
}
}