Uniform unmarshal function

This commit is contained in:
Donny Xia
2020-07-14 17:01:11 -07:00
parent ec9ae3d7b0
commit 897698fb29
4 changed files with 44 additions and 13 deletions

View File

@@ -153,7 +153,7 @@ func (mf *kustomizationFile) Read() (*types.Kustomization, error) {
return nil, err
}
var k types.Kustomization
err = yaml.Unmarshal(data, &k)
err = k.Unmarshal(data)
if err != nil {
return nil, err
}

View File

@@ -340,3 +340,21 @@ kind: Kustomization
string(expected), string(bytes))
}
}
func TestUnknownFieldInKustomization(t *testing.T) {
kContent := []byte(`
foo:
bar
`)
fSys := filesys.MakeFsInMemory()
testutils_test.WriteTestKustomizationWith(fSys, kContent)
mf, err := NewKustomizationFile(fSys)
if err != nil {
t.Fatalf("Unexpected Error: %v", err)
}
_, err = mf.Read()
if err == nil || err.Error() != "json: unknown field \"foo\"" {
t.Fatalf("Expect an unknown field error but got: %v", err)
}
}