@@ -16,6 +16,7 @@ import (
16
16
"github.com/mongodb/mongo-go-driver/bson/bsonrw"
17
17
"github.com/mongodb/mongo-go-driver/bson/bsonrw/bsonrwtest"
18
18
"github.com/mongodb/mongo-go-driver/bson/bsontype"
19
+ "github.com/mongodb/mongo-go-driver/x/bsonx"
19
20
)
20
21
21
22
func TestBasicDecode (t * testing.T ) {
@@ -138,6 +139,26 @@ func TestDecoderv2(t *testing.T) {
138
139
}
139
140
})
140
141
})
142
+ t .Run ("Decode doesn't zero struct" , func (t * testing.T ) {
143
+ type foo struct {
144
+ Item string
145
+ Qty int
146
+ Bonus int
147
+ }
148
+ var got foo
149
+ got .Item = "apple"
150
+ got .Bonus = 2
151
+ data := docToBytes (bsonx.Doc {{"item" , bsonx .String ("canvas" )}, {"qty" , bsonx .Int32 (4 )}})
152
+ vr := bsonrw .NewBSONDocumentReader (data )
153
+ dec , err := NewDecoder (DefaultRegistry , vr )
154
+ noerr (t , err )
155
+ err = dec .Decode (& got )
156
+ noerr (t , err )
157
+ want := foo {Item : "canvas" , Qty : 4 , Bonus : 2 }
158
+ if ! reflect .DeepEqual (got , want ) {
159
+ t .Errorf ("Results do not match. got %+v; want %+v" , got , want )
160
+ }
161
+ })
141
162
t .Run ("Reset" , func (t * testing.T ) {
142
163
vr1 , vr2 := bsonrw .NewBSONDocumentReader ([]byte {}), bsonrw .NewBSONDocumentReader ([]byte {})
143
164
dec , err := NewDecoder (DefaultRegistry , vr1 )
0 commit comments