@@ -10,64 +10,42 @@ import (
1010 "reflect"
1111 "testing"
1212
13- "github.com/google/go-cmp/cmp "
13+ "github.com/stretchr/testify/assert "
1414 "go.mongodb.org/mongo-driver/bson/bsoncodec"
1515 "go.mongodb.org/mongo-driver/bson/bsonrw"
16- "go.mongodb.org/mongo-driver/internal/testutil/assert"
1716 "go.mongodb.org/mongo-driver/x/bsonx/bsoncore"
1817)
1918
2019func TestUnmarshal (t * testing.T ) {
21- for _ , tc := range unmarshalingTestCases {
20+ for _ , tc := range unmarshalingTestCases () {
2221 t .Run (tc .name , func (t * testing.T ) {
23- if tc .reg != nil {
24- t .Skip () // test requires custom registry
25- }
2622 got := reflect .New (tc .sType ).Interface ()
2723 err := Unmarshal (tc .data , got )
2824 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." )
3226 })
3327 }
3428}
3529
3630func TestUnmarshalWithRegistry (t * testing.T ) {
37- for _ , tc := range unmarshalingTestCases {
31+ for _ , tc := range unmarshalingTestCases () {
3832 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- }
4533 got := reflect .New (tc .sType ).Interface ()
46- err := UnmarshalWithRegistry (reg , tc .data , got )
34+ err := UnmarshalWithRegistry (DefaultRegistry , tc .data , got )
4735 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." )
5137 })
5238 }
5339}
5440
5541func TestUnmarshalWithContext (t * testing.T ) {
56- for _ , tc := range unmarshalingTestCases {
42+ for _ , tc := range unmarshalingTestCases () {
5743 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 }
6545 got := reflect .New (tc .sType ).Interface ()
6646 err := UnmarshalWithContext (dc , tc .data , got )
6747 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." )
7149 })
7250 }
7351}
@@ -80,9 +58,7 @@ func TestUnmarshalExtJSONWithRegistry(t *testing.T) {
8058 err := UnmarshalExtJSONWithRegistry (DefaultRegistry , data , true , & got )
8159 noerr (t , err )
8260 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." )
8662 })
8763
8864 t .Run ("UnmarshalExtJSONInvalidInput" , func (t * testing.T ) {
@@ -165,9 +141,7 @@ func TestUnmarshalExtJSONWithContext(t *testing.T) {
165141 dc := bsoncodec.DecodeContext {Registry : DefaultRegistry }
166142 err := UnmarshalExtJSONWithContext (dc , tc .data , true , got )
167143 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." )
171145 })
172146 }
173147}
0 commit comments