Skip to content

Commit 4d68f59

Browse files
prestonvasquezmatthewdale
authored andcommitted
GODRIVER-2570 update bsoncore value string to preserve timestamp type (#1150)
1 parent 667bfcf commit 4d68f59

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

x/bsonx/bsoncore/value.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ func (v Value) String() string {
323323
if !ok {
324324
return ""
325325
}
326-
return fmt.Sprintf(`{"$timestamp":{"t":"%s","i":"%s"}}`, strconv.FormatUint(uint64(t), 10), strconv.FormatUint(uint64(i), 10))
326+
return fmt.Sprintf(`{"$timestamp":{"t":%v,"i":%v}}`, t, i)
327327
case bsontype.Int64:
328328
i64, ok := v.Int64OK()
329329
if !ok {

x/bsonx/bsoncore/value_test.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,14 @@ import (
1717
)
1818

1919
func TestValue(t *testing.T) {
20+
t.Parallel()
21+
2022
t.Run("Validate", func(t *testing.T) {
23+
t.Parallel()
24+
2125
t.Run("invalid", func(t *testing.T) {
26+
t.Parallel()
27+
2228
v := Value{Type: bsontype.Double, Data: []byte{0x01, 0x02, 0x03, 0x04}}
2329
want := NewInsufficientBytesError(v.Data, v.Data)
2430
got := v.Validate()
@@ -27,6 +33,8 @@ func TestValue(t *testing.T) {
2733
}
2834
})
2935
t.Run("value", func(t *testing.T) {
36+
t.Parallel()
37+
3038
v := Value{Type: bsontype.Double, Data: AppendDouble(nil, 3.14159)}
3139
var want error
3240
got := v.Validate()
@@ -35,7 +43,10 @@ func TestValue(t *testing.T) {
3543
}
3644
})
3745
})
46+
3847
t.Run("IsNumber", func(t *testing.T) {
48+
t.Parallel()
49+
3950
testCases := []struct {
4051
name string
4152
val Value
@@ -50,7 +61,11 @@ func TestValue(t *testing.T) {
5061
}
5162

5263
for _, tc := range testCases {
64+
tc := tc
65+
5366
t.Run(tc.name, func(t *testing.T) {
67+
t.Parallel()
68+
5469
isnum := tc.val.IsNumber()
5570
if isnum != tc.isnum {
5671
t.Errorf("IsNumber did not return the expected boolean. got %t; want %t", isnum, tc.isnum)
@@ -619,10 +634,19 @@ func TestValue(t *testing.T) {
619634
nil,
620635
[]interface{}{primitive.NewDecimal128(12345, 67890), true},
621636
},
637+
{
638+
"Timestamp.String/Success", Value.String, Value{Type: bsontype.Timestamp, Data: AppendTimestamp(nil, 12345, 67890)},
639+
nil,
640+
[]interface{}{"{\"$timestamp\":{\"t\":12345,\"i\":67890}}"},
641+
},
622642
}
623643

624644
for _, tc := range testCases {
645+
tc := tc
646+
625647
t.Run(tc.name, func(t *testing.T) {
648+
t.Parallel()
649+
626650
defer func() {
627651
err := recover()
628652
if !cmp.Equal(err, tc.panicErr, cmp.Comparer(compareErrors)) {

0 commit comments

Comments
 (0)