-
Notifications
You must be signed in to change notification settings - Fork 239
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replace json-based implementation of DeepCopy on GenericMap
- Loading branch information
Showing
2 changed files
with
55 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package v1alpha1 | ||
|
||
import ( | ||
"testing" | ||
|
||
"k8s.io/apimachinery/pkg/api/equality" | ||
) | ||
|
||
func Test_deepCopyMap(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
src map[string]interface{} | ||
}{ | ||
{name: "copies top-level keys", src: map[string]interface{}{ | ||
"str": "value", | ||
"list": []any{1, "dos", true}, | ||
"boolean": false, | ||
}}, | ||
{name: "copies nested values", src: map[string]interface{}{ | ||
"first": map[string]any{ | ||
"second": map[string]any{ | ||
"third": map[string]any{ | ||
"str": "value", | ||
"boolean": false, | ||
}, | ||
"list": []any{1, "dos", true}, | ||
"boolean": false, | ||
}, | ||
}, | ||
}}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
res := map[string]interface{}{} | ||
deepCopyMap(tt.src, res) | ||
if !equality.Semantic.DeepEqual(tt.src, res) { | ||
t.Errorf("result object is not identical: %+v", res) | ||
} | ||
}) | ||
} | ||
} |