Skip to content

Commit 3e6d365

Browse files
rfblue2Roland Fong
authored and
Roland Fong
committed
Implement ObjectID Test Plan
GODRIVER-509 Change-Id: I42d7b0f402f8de096fc6cc12e9ad9afed4dbbcae
1 parent 0a84d58 commit 3e6d365

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

bson/objectid/objectid_test.go

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ package objectid
99
import (
1010
"testing"
1111

12+
"encoding/binary"
13+
"time"
14+
1215
"github.com/stretchr/testify/require"
1316
)
1417

@@ -39,3 +42,42 @@ func TestFromHex_WrongLength(t *testing.T) {
3942
_, err := FromHex("deadbeef")
4043
require.Equal(t, ErrInvalidHex, err)
4144
}
45+
46+
func TestTimeStamp(t *testing.T) {
47+
testCases := []struct {
48+
Hex string
49+
Expected string
50+
}{
51+
{
52+
"000000001111111111111111",
53+
"1970-01-01 00:00:00 +0000 UTC",
54+
},
55+
{
56+
"7FFFFFFF1111111111111111",
57+
"2038-01-19 03:14:07 +0000 UTC",
58+
},
59+
{
60+
"800000001111111111111111",
61+
"2038-01-19 03:14:08 +0000 UTC",
62+
},
63+
{
64+
"FFFFFFFF1111111111111111",
65+
"2106-02-07 06:28:15 +0000 UTC",
66+
},
67+
}
68+
69+
for _, testcase := range testCases {
70+
id, err := FromHex(testcase.Hex)
71+
require.NoError(t, err)
72+
secs := int64(binary.BigEndian.Uint32(id[0:4]))
73+
timestamp := time.Unix(secs, 0).UTC()
74+
require.Equal(t, testcase.Expected, timestamp.String())
75+
}
76+
77+
}
78+
79+
func TestCounterOverflow(t *testing.T) {
80+
objectIDCounter = 0xFFFFFFFF
81+
New()
82+
require.Equal(t, uint32(0), objectIDCounter)
83+
}

0 commit comments

Comments
 (0)