@@ -10,64 +10,42 @@ import (
10
10
"reflect"
11
11
"testing"
12
12
13
- "github.com/google/go-cmp/cmp "
13
+ "github.com/stretchr/testify/assert "
14
14
"go.mongodb.org/mongo-driver/bson/bsoncodec"
15
15
"go.mongodb.org/mongo-driver/bson/bsonrw"
16
- "go.mongodb.org/mongo-driver/internal/testutil/assert"
17
16
"go.mongodb.org/mongo-driver/x/bsonx/bsoncore"
18
17
)
19
18
20
19
func TestUnmarshal (t * testing.T ) {
21
- for _ , tc := range unmarshalingTestCases {
20
+ for _ , tc := range unmarshalingTestCases () {
22
21
t .Run (tc .name , func (t * testing.T ) {
23
- if tc .reg != nil {
24
- t .Skip () // test requires custom registry
25
- }
26
22
got := reflect .New (tc .sType ).Interface ()
27
23
err := Unmarshal (tc .data , got )
28
24
noerr (t , err )
29
- if ! cmp .Equal (got , tc .want ) {
30
- t .Errorf ("Did not unmarshal as expected. got %v; want %v" , got , tc .want )
31
- }
25
+ assert .Equal (t , tc .want , got , "Did not unmarshal as expected." )
32
26
})
33
27
}
34
28
}
35
29
36
30
func TestUnmarshalWithRegistry (t * testing.T ) {
37
- for _ , tc := range unmarshalingTestCases {
31
+ for _ , tc := range unmarshalingTestCases () {
38
32
t .Run (tc .name , func (t * testing.T ) {
39
- var reg * bsoncodec.Registry
40
- if tc .reg != nil {
41
- reg = tc .reg
42
- } else {
43
- reg = DefaultRegistry
44
- }
45
33
got := reflect .New (tc .sType ).Interface ()
46
- err := UnmarshalWithRegistry (reg , tc .data , got )
34
+ err := UnmarshalWithRegistry (DefaultRegistry , tc .data , got )
47
35
noerr (t , err )
48
- if ! cmp .Equal (got , tc .want ) {
49
- t .Errorf ("Did not unmarshal as expected. got %v; want %v" , got , tc .want )
50
- }
36
+ assert .Equal (t , tc .want , got , "Did not unmarshal as expected." )
51
37
})
52
38
}
53
39
}
54
40
55
41
func TestUnmarshalWithContext (t * testing.T ) {
56
- for _ , tc := range unmarshalingTestCases {
42
+ for _ , tc := range unmarshalingTestCases () {
57
43
t .Run (tc .name , func (t * testing.T ) {
58
- var reg * bsoncodec.Registry
59
- if tc .reg != nil {
60
- reg = tc .reg
61
- } else {
62
- reg = DefaultRegistry
63
- }
64
- dc := bsoncodec.DecodeContext {Registry : reg }
44
+ dc := bsoncodec.DecodeContext {Registry : DefaultRegistry }
65
45
got := reflect .New (tc .sType ).Interface ()
66
46
err := UnmarshalWithContext (dc , tc .data , got )
67
47
noerr (t , err )
68
- if ! cmp .Equal (got , tc .want ) {
69
- t .Errorf ("Did not unmarshal as expected. got %v; want %v" , got , tc .want )
70
- }
48
+ assert .Equal (t , tc .want , got , "Did not unmarshal as expected." )
71
49
})
72
50
}
73
51
}
@@ -80,9 +58,7 @@ func TestUnmarshalExtJSONWithRegistry(t *testing.T) {
80
58
err := UnmarshalExtJSONWithRegistry (DefaultRegistry , data , true , & got )
81
59
noerr (t , err )
82
60
want := teststruct {1 }
83
- if ! cmp .Equal (got , want ) {
84
- t .Errorf ("Did not unmarshal as expected. got %v; want %v" , got , want )
85
- }
61
+ assert .Equal (t , want , got , "Did not unmarshal as expected." )
86
62
})
87
63
88
64
t .Run ("UnmarshalExtJSONInvalidInput" , func (t * testing.T ) {
@@ -165,9 +141,7 @@ func TestUnmarshalExtJSONWithContext(t *testing.T) {
165
141
dc := bsoncodec.DecodeContext {Registry : DefaultRegistry }
166
142
err := UnmarshalExtJSONWithContext (dc , tc .data , true , got )
167
143
noerr (t , err )
168
- if ! cmp .Equal (got , tc .want ) {
169
- t .Errorf ("Did not unmarshal as expected. got %+v; want %+v" , got , tc .want )
170
- }
144
+ assert .Equal (t , tc .want , got , "Did not unmarshal as expected." )
171
145
})
172
146
}
173
147
}
0 commit comments