diff --git a/pkg/test/step.go b/pkg/test/step.go index 51b36b87f..7c4376d52 100644 --- a/pkg/test/step.go +++ b/pkg/test/step.go @@ -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) diff --git a/pkg/test/step_integration_test.go b/pkg/test/step_integration_test.go index 7d2cea7fa..0f5d94195 100644 --- a/pkg/test/step_integration_test.go +++ b/pkg/test/step_integration_test.go @@ -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, "-")) diff --git a/test/integration/list-pods/00-assert.yaml b/test/integration/list-pods/00-assert.yaml deleted file mode 100644 index a51a3b688..000000000 --- a/test/integration/list-pods/00-assert.yaml +++ /dev/null @@ -1,9 +0,0 @@ -apiVersion: v1 -kind: Pod -metadata: - labels: - app: nginx -spec: - containers: - - name: nginx - image: nginx:1.7.9 diff --git a/test/integration/list-pods/00-deployment.yaml b/test/integration/list-pods/00-deployment.yaml deleted file mode 100644 index 9db3ea830..000000000 --- a/test/integration/list-pods/00-deployment.yaml +++ /dev/null @@ -1,16 +0,0 @@ -apiVersion: apps/v1 -kind: Deployment -metadata: - name: nginx-deployment -spec: - selector: - matchLabels: - app: nginx - template: - metadata: - labels: - app: nginx - spec: - containers: - - name: nginx - image: nginx:1.7.9