-
Notifications
You must be signed in to change notification settings - Fork 4
/
bson_test.go
47 lines (39 loc) · 981 Bytes
/
bson_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package utils
import (
"testing"
"time"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func BenchmarkTimeFromObjectIDHex(_ *testing.B) {
cases := []string{
"63acfc824ffda9000ee65045",
"5c4b288bac1b2972d0291377",
}
for _, v := range cases {
_, _ = TimeFromObjectIDHex(v)
}
}
func TestTimeFromObjectIDHex(t *testing.T) {
t.Run("valid hex objectID", func(t *testing.T) {
cases := map[string]time.Time{
"63acfc824ffda9000ee65045": time.Date(2022, time.December, 29, 2, 33, 38, 0, time.UTC),
"5c4b288bac1b2972d0291377": time.Date(2019, time.January, 25, 15, 17, 31, 0, time.UTC),
}
for k, v := range cases {
r, err := TimeFromObjectIDHex(k)
require.NoError(t, err)
assert.Equal(t, v.UTC(), r.UTC())
}
})
t.Run("invalid hex objectID", func(t *testing.T) {
cases := []string{
"anuanu",
"876124892",
}
for _, c := range cases {
_, err := TimeFromObjectIDHex(c)
require.Error(t, err)
}
})
}