diff --git a/pkg/diff/diff_test.go b/pkg/diff/diff_test.go index 922db590e..9305beb5a 100644 --- a/pkg/diff/diff_test.go +++ b/pkg/diff/diff_test.go @@ -1152,6 +1152,29 @@ spec: assert.Equal(t, "200m", requestsAfter["cpu"]) } +func TestRemarshalResources_stripTypes_unknownField(t *testing.T) { + un := unstructured.Unstructured{Object: map[string]interface{}{ + "apiVersion": "v1", + "kind": "Pod", + "spec": map[string]interface{}{ + "containers": []interface{}{ + map[string]interface{}{ + "resources": map[string]interface{}{ + "requests": map[string]interface{}{ + "cpu": 0.2, + }, + }, + }, + }, + }, + "unknownField": "unknown", + }} + afterUn := remarshal(&un, applyOptions(diffOptionsForTest())) + requestsAfter := afterUn.Object["spec"].(map[string]interface{})["containers"].([]interface{})[0].(map[string]interface{})["resources"].(map[string]interface{})["requests"].(map[string]interface{}) + // Since there's an unknown field, we can't unmarshal into the Pod type, so the field doesn't get normalized to "200m". + assert.Equal(t, float64(0.2), requestsAfter["cpu"]) +} + func ExampleDiff() { expectedResource := unstructured.Unstructured{} if err := yaml.Unmarshal([]byte(`