Skip to content

Commit f1e8a1d

Browse files
GODRIVER-3470 Add test case for an initialized ptr
1 parent dc02142 commit f1e8a1d

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

bson/unmarshaling_cases_test.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,12 @@ package bson
88

99
import (
1010
"reflect"
11+
"testing"
1112

1213
"go.mongodb.org/mongo-driver/bson/bsonrw"
1314
"go.mongodb.org/mongo-driver/bson/bsontype"
15+
"go.mongodb.org/mongo-driver/internal/assert"
16+
"go.mongodb.org/mongo-driver/internal/require"
1417
)
1518

1619
type unmarshalingTestCase struct {
@@ -295,3 +298,20 @@ func (ms *unmarshalCallTracker) UnmarshalBSONValue(bsontype.Type, []byte) error
295298

296299
return nil
297300
}
301+
302+
func TestInitializedPointerDataWithBSONNull(t *testing.T) {
303+
// Set up the test case with an initialized pointer.
304+
tc := unmarshalBehaviorTestCase{
305+
PtrTracker: &unmarshalCallTracker{},
306+
}
307+
308+
// Create BSON data where the 'ptr_tracker' field is explicitly set to null.
309+
bytes := docToBytes(D{{Key: "ptr_tracker", Value: nil}})
310+
311+
// Unmarshal the BSON data into the test case struct.
312+
// This should set PtrTracker to nil due to the BSON null value.
313+
err := Unmarshal(bytes, &tc)
314+
require.NoError(t, err)
315+
316+
assert.Nil(t, tc.PtrTracker)
317+
}

0 commit comments

Comments
 (0)