Add BsonDFromSlice, Add AssertDeepEqual
This commit is contained in:
20
assert.go
Normal file
20
assert.go
Normal file
@@ -0,0 +1,20 @@
|
||||
package commons
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"bytes"
|
||||
|
||||
"go.mongodb.org/mongo-driver/v2/bson"
|
||||
)
|
||||
|
||||
// AssertDeepEqual compares equality by comparing bytes.
|
||||
func AssertDeepEqual(t *testing.T, expected, actual any) {
|
||||
t.Helper()
|
||||
|
||||
expJSON, _ := bson.MarshalExtJSON(expected, true, true)
|
||||
actJSON, _ := bson.MarshalExtJSON(actual, true, true)
|
||||
|
||||
if !bytes.Equal(expJSON, actJSON) {
|
||||
t.Fatalf("expected %s, got %s", expJSON, actJSON)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user