Skip to content

Commit

Permalink
Add additional tests for document validation. Correct typos
Browse files Browse the repository at this point in the history
  • Loading branch information
quintush committed Jan 2, 2023
1 parent e35f027 commit 83cff9e
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
4 changes: 2 additions & 2 deletions pkg/unittest/validators/contains_document_validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ func (v ContainsDocumentValidator) Validate(context *ValidateContext) (bool, []s
continue
}
if !validateSuccess {
errorMesasge := v.failInfo(v.Kind, 0, context.Negative)
validateErrors = append(validateErrors, errorMesasge...)
errorMessage := v.failInfo(v.Kind, 0, context.Negative)
validateErrors = append(validateErrors, errorMessage...)
}
validateSuccess = determineSuccess(1, validateSuccess, true)

Expand Down
24 changes: 23 additions & 1 deletion pkg/unittest/validators/contains_document_validator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ func TestContainsDocumentValidatorNoNameNamespaceWhenOk(t *testing.T) {
assert.Equal(t, []string{}, diff)
}

func TestContainsDocumentValidatorWhenFail(t *testing.T) {
func TestContainsDocumentValidatorWhenFailKind(t *testing.T) {
validator := ContainsDocumentValidator{
"Deployment",
"apps/v1",
Expand All @@ -133,3 +133,25 @@ func TestContainsDocumentValidatorWhenFail(t *testing.T) {
"\tKind = Deployment, apiVersion = apps/v1",
}, diff)
}

func TestContainsDocumentValidatorWhenFailAPIVersion(t *testing.T) {
validator := ContainsDocumentValidator{
"Service",
"apps/v1",
"foo",
"bar",
}

pass, diff := validator.Validate(&ValidateContext{
Index: -1,
Docs: []common.K8sManifest{makeManifest(docToTestContainsDocument1),
makeManifest(docToTestContainsDocument2)},
})

assert.False(t, pass)
assert.Equal(t, []string{
"DocumentIndex:\t0",
"Expected to contain document:",
"\tKind = Service, apiVersion = apps/v1",
}, diff)
}

0 comments on commit 83cff9e

Please sign in to comment.