Skip to content

Commit

Permalink
Fixed most tests
Browse files Browse the repository at this point in the history
  • Loading branch information
bdun1013 committed Mar 4, 2020
1 parent 9da0ce6 commit 903b80e
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 10 deletions.
4 changes: 2 additions & 2 deletions unittest/assertion.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion unittest/assertion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions unittest/validators/contains_validator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down Expand Up @@ -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},
Expand Down
2 changes: 1 addition & 1 deletion unittest/validators/equal_validator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 3 additions & 1 deletion unittest/valueutils/valueutils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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),
Expand Down
6 changes: 3 additions & 3 deletions unittest/valueutils/valueutils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 903b80e

Please sign in to comment.