Skip to content

Commit

Permalink
test unknown field case
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Crenshaw <[email protected]>
  • Loading branch information
crenshaw-dev committed Sep 17, 2024
1 parent f416878 commit 8c91416
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions pkg/diff/diff_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(`
Expand Down

0 comments on commit 8c91416

Please sign in to comment.