Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup cluster resources when test fails #503

Merged
merged 1 commit into from
Mar 30, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 18 additions & 14 deletions test/eventlistener_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ func TestEventListenerCreate(t *testing.T) {
c, namespace := setup(t)
t.Parallel()

defer tearDown(t, c, namespace)
knativetest.CleanupOnInterrupt(func() { tearDown(t, c, namespace) }, t.Logf)
defer cleanup(t, c, namespace)
knativetest.CleanupOnInterrupt(func() { cleanup(t, c, namespace) }, t.Logf)

t.Log("Start EventListener e2e test")

Expand Down Expand Up @@ -385,18 +385,6 @@ func TestEventListenerCreate(t *testing.T) {
t.Fatalf("Failed to delete EventListener Service: %s", err)
}
t.Log("EventListener's Service was deleted")

// Cleanup cluster-scoped resources
t.Logf("Deleting cluster-scoped resources")
if err := c.KubeClient.RbacV1().ClusterRoles().Delete("my-role", &metav1.DeleteOptions{}); err != nil {
t.Errorf("Failed to delete clusterrole my-role: %s", err)
}
if err := c.KubeClient.RbacV1().ClusterRoleBindings().Delete("my-rolebinding", &metav1.DeleteOptions{}); err != nil {
t.Errorf("Failed to delete clusterrolebinding my-rolebinding: %s", err)
}
if err := c.TriggersClient.TriggersV1alpha1().ClusterTriggerBindings().Delete("my-clustertriggerbinding", &metav1.DeleteOptions{}); err != nil {
t.Errorf("Failed to delete clustertriggerbinding my-clustertriggerbinding: %s", err)
}
}

// The structure of this field corresponds to values for the `license` key in
Expand Down Expand Up @@ -435,3 +423,19 @@ func compareParamsWithLicenseJSON(x, y v1alpha1.ResourceParam) bool {
}
return false
}

func cleanup(t *testing.T, c *clients, n string) {
t.Helper()
tearDown(t, c, n)
// Cleanup cluster-scoped resources
t.Logf("Deleting cluster-scoped resources")
if err := c.KubeClient.RbacV1().ClusterRoles().Delete("my-role", &metav1.DeleteOptions{}); err != nil {
t.Errorf("Failed to delete clusterrole my-role: %s", err)
}
if err := c.KubeClient.RbacV1().ClusterRoleBindings().Delete("my-rolebinding", &metav1.DeleteOptions{}); err != nil {
t.Errorf("Failed to delete clusterrolebinding my-rolebinding: %s", err)
}
if err := c.TriggersClient.TriggersV1alpha1().ClusterTriggerBindings().Delete("my-clustertriggerbinding", &metav1.DeleteOptions{}); err != nil {
t.Errorf("Failed to delete clustertriggerbinding my-clustertriggerbinding: %s", err)
}
}