K8s/Unstructured: Avoid panic in DeepCopy (#99840)

This commit is contained in:
Ryan McKinley
2025-01-31 00:19:09 +02:00
committed by GitHub
parent 8ce8c1635f
commit e3d9b6cadf
2 changed files with 97 additions and 1 deletions
@@ -0,0 +1,44 @@
package v0alpha1
import (
"encoding/json"
"testing"
"github.com/stretchr/testify/require"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
func TestDeepCopyJSON(t *testing.T) {
obj := &Unstructured{
Object: map[string]interface{}{
"int": int(2),
"int16": int16(2),
"int32": int32(2),
"uint64": uint64(2),
"ref": &ObjectReference{
Resource: "x",
},
"array": []any{
int(1), int64(2), "hello",
},
"string": "hello",
"bool": true,
"map": map[string]any{
"x": &ObjectReference{
Resource: "x",
},
},
"object": &v1.APIGroup{
Name: "HELLO",
},
},
}
before, err := json.Marshal(obj)
require.NoError(t, err)
clone := obj.DeepCopy()
after, err := json.Marshal(clone)
require.NoError(t, err)
require.JSONEq(t, string(before), string(after))
}