diff --git a/unittest/assertion.go b/unittest/assertion.go index b6317907..91285f12 100644 --- a/unittest/assertion.go +++ b/unittest/assertion.go @@ -56,7 +56,7 @@ func (a *Assertion) noFileErrMessage() string { // UnmarshalYAML implement yaml.Unmalshaler, construct validator according to the assert type func (a *Assertion) UnmarshalYAML(unmarshal func(interface{}) error) error { - assertDef := make(map[string]interface{}) + assertDef := make(map[interface{}]interface{}) if err := unmarshal(&assertDef); err != nil { return err } @@ -87,7 +87,7 @@ func (a *Assertion) UnmarshalYAML(unmarshal func(interface{}) error) error { return nil } -func (a *Assertion) constructValidator(assertDef map[string]interface{}) error { +func (a *Assertion) constructValidator(assertDef map[interface{}]interface{}) error { for assertName, correspondDef := range assertTypeMapping { if params, ok := assertDef[assertName]; ok { if a.validator != nil { diff --git a/unittest/assertion_test.go b/unittest/assertion_test.go index 4df18554..a39eaaf1 100644 --- a/unittest/assertion_test.go +++ b/unittest/assertion_test.go @@ -26,7 +26,7 @@ func TestAssertionUnmarshaledFromYAML(t *testing.T) { - isAPIVersion: - hasDocuments: ` - assertionsAsMap := make([]map[string]interface{}, 13) + assertionsAsMap := make([]map[interface{}]interface{}, 13) yaml.Unmarshal([]byte(assertionsYAML), &assertionsAsMap) assertions := make([]Assertion, 13) yaml.Unmarshal([]byte(assertionsYAML), &assertions) diff --git a/unittest/validators/contains_validator_test.go b/unittest/validators/contains_validator_test.go index bfe4b29c..d4244197 100644 --- a/unittest/validators/contains_validator_test.go +++ b/unittest/validators/contains_validator_test.go @@ -21,7 +21,7 @@ func TestContainsValidatorWhenOk(t *testing.T) { validator := ContainsValidator{ "a.b", - map[string]interface{}{"d": "foo bar"}, + map[interface{}]interface{}{"d": "foo bar"}, } pass, diff := validator.Validate(&ValidateContext{ Docs: []common.K8sManifest{manifest}, @@ -71,7 +71,7 @@ func TestContainsValidatorWhenNegativeAndFail(t *testing.T) { validator := ContainsValidator{ "a.b", - map[string]interface{}{"d": "foo bar"}, + map[interface{}]interface{}{"d": "foo bar"}, } pass, diff := validator.Validate(&ValidateContext{ Docs: []common.K8sManifest{manifest}, diff --git a/unittest/validators/equal_validator_test.go b/unittest/validators/equal_validator_test.go index 45267bf3..4f8bd86a 100644 --- a/unittest/validators/equal_validator_test.go +++ b/unittest/validators/equal_validator_test.go @@ -70,7 +70,7 @@ func TestEqualValidatorWhenFail(t *testing.T) { func TestEqualValidatorWhenNegativeAndFail(t *testing.T) { manifest := makeManifest(docToTestEqual) - v := EqualValidator{"a.b[0]", map[string]interface{}{"c": 123}} + v := EqualValidator{"a.b[0]", map[interface{}]interface{}{"c": 123}} pass, diff := v.Validate(&ValidateContext{ Docs: []common.K8sManifest{manifest}, Negative: true, diff --git a/unittest/valueutils/valueutils.go b/unittest/valueutils/valueutils.go index d00dab3e..0409b230 100644 --- a/unittest/valueutils/valueutils.go +++ b/unittest/valueutils/valueutils.go @@ -45,13 +45,14 @@ type fetchTraverser struct { } func (tr *fetchTraverser) traverseMapKey(key string) error { - if d, ok := tr.data.(map[string]interface{}); ok { + if d, ok := tr.data.(map[interface{}]interface{}); ok { tr.data = d[key] return nil } else if d, ok := tr.data.(common.K8sManifest); ok { tr.data = d[key] return nil } + return fmt.Errorf( "can't get [\"%s\"] from a non map type:\n%s", key, common.TrustedMarshalYAML(tr.data), @@ -66,6 +67,7 @@ func (tr *fetchTraverser) traverseListIdx(idx int) error { tr.data = d[idx] return nil } + return fmt.Errorf( "can't get [%d] from a non array type:\n%s", idx, common.TrustedMarshalYAML(tr.data), diff --git a/unittest/valueutils/valueutils_test.go b/unittest/valueutils/valueutils_test.go index 7cef44a8..39cbfac9 100644 --- a/unittest/valueutils/valueutils_test.go +++ b/unittest/valueutils/valueutils_test.go @@ -11,15 +11,15 @@ import ( func TestGetValueOfSetPath(t *testing.T) { a := assert.New(t) data := common.K8sManifest{ - "a": map[string]interface{}{ - "b": []interface{}{"_", map[string]interface{}{"c": "yes"}}, + "a": map[interface{}]interface{}{ + "b": []interface{}{"_", map[interface{}]interface{}{"c": "yes"}}, }, } var expectionsMapping = map[string]interface{}{ "a.b[1].c": "yes", "a.b[0]": "_", - "a.b": []interface{}{"_", map[string]interface{}{"c": "yes"}}, + "a.b": []interface{}{"_", map[interface{}]interface{}{"c": "yes"}}, } for path, expect := range expectionsMapping {