Skip to content

Commit

Permalink
GODRIVER-3470 Add test case for an initialized ptr
Browse files Browse the repository at this point in the history
  • Loading branch information
prestonvasquez committed Jan 29, 2025
1 parent dc02142 commit f1e8a1d
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions bson/unmarshaling_cases_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,12 @@ package bson

import (
"reflect"
"testing"

"go.mongodb.org/mongo-driver/bson/bsonrw"
"go.mongodb.org/mongo-driver/bson/bsontype"
"go.mongodb.org/mongo-driver/internal/assert"
"go.mongodb.org/mongo-driver/internal/require"
)

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

return nil
}

func TestInitializedPointerDataWithBSONNull(t *testing.T) {
// Set up the test case with an initialized pointer.
tc := unmarshalBehaviorTestCase{
PtrTracker: &unmarshalCallTracker{},
}

// Create BSON data where the 'ptr_tracker' field is explicitly set to null.
bytes := docToBytes(D{{Key: "ptr_tracker", Value: nil}})

// Unmarshal the BSON data into the test case struct.
// This should set PtrTracker to nil due to the BSON null value.
err := Unmarshal(bytes, &tc)
require.NoError(t, err)

assert.Nil(t, tc.PtrTracker)
}

0 comments on commit f1e8a1d

Please sign in to comment.