Add bson clone

This commit is contained in:
George Suntres
2026-04-23 15:37:20 -04:00
parent 0ce3f3b5eb
commit 28dcfb9e4c
2 changed files with 77 additions and 1 deletions

View File

@@ -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")
}
}