Skip to content

Commit

Permalink
Ensure that test harness returns an error if no resources exist when …
Browse files Browse the repository at this point in the history
…listing (#521)

* Remove integration test list-pods - it does not test KUDO.

* Integration tests should return an error if no resources match when listing resources.

* fix formatting
  • Loading branch information
jbarrick-mesosphere committed Jul 8, 2019
1 parent 73e29ce commit 919881a
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 25 deletions.
4 changes: 4 additions & 0 deletions pkg/test/step.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,10 @@ func (s *Step) CheckResource(expected runtime.Object, namespace string) []error
for index := range actual.Items {
actuals = append(actuals, &actual.Items[index])
}

if len(actual.Items) == 0 {
testErrors = append(testErrors, fmt.Errorf("no resources matched of kind: %s", gvk.String()))
}
}
if err != nil {
return append(testErrors, err)
Expand Down
24 changes: 24 additions & 0 deletions pkg/test/step_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,30 @@ func TestCheckResourceIntegration(t *testing.T) {
},
shouldError: true,
},
{
testName: "step should fail if there are no objects of the same type in the namespace",
actual: []runtime.Object{},
expected: &unstructured.Unstructured{
Object: map[string]interface{}{
"apiVersion": "v1",
"kind": "Pod",
"metadata": map[string]interface{}{
"labels": map[string]interface{}{
"app": "nginx",
},
},
"spec": map[string]interface{}{
"containers": []interface{}{
map[string]interface{}{
"image": "nginx:1.7.9",
"name": "nginx",
},
},
},
},
},
shouldError: true,
},
} {
t.Run(test.testName, func(t *testing.T) {
namespace := fmt.Sprintf("kudo-test-%s", petname.Generate(2, "-"))
Expand Down
9 changes: 0 additions & 9 deletions test/integration/list-pods/00-assert.yaml

This file was deleted.

16 changes: 0 additions & 16 deletions test/integration/list-pods/00-deployment.yaml

This file was deleted.

0 comments on commit 919881a

Please sign in to comment.