Add bson clone
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package commons
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
)
|
||||
|
||||
@@ -307,4 +308,31 @@ func TestMapMerge(t *testing.T) {
|
||||
if len(m) != 4 {
|
||||
t.Fatalf("Merged map should have lenght 4 not %d", len(m))
|
||||
}
|
||||
}
|
||||
|
||||
func TestBsonClone(t *testing.T) {
|
||||
orig := map[string]any{
|
||||
"name": "Kolias",
|
||||
"age": int32(56),
|
||||
"salary": int64(100000000),
|
||||
"meta": map[string]any{
|
||||
"num1": int32(110),
|
||||
},
|
||||
}
|
||||
|
||||
clone := BsonClone(orig)
|
||||
|
||||
if "int32" != fmt.Sprintf("%T", clone["age"]) {
|
||||
t.Fatalf("int32 should map to int32")
|
||||
}
|
||||
|
||||
if "int64" != fmt.Sprintf("%T", clone["salary"]) {
|
||||
t.Fatalf("int64 should map to int64")
|
||||
}
|
||||
|
||||
meta := clone["meta"].(map[string]any)
|
||||
|
||||
if "int32" != fmt.Sprintf("%T", meta["num1"]) {
|
||||
t.Fatalf("netsted type should have been int32")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user