Skip to content

Commit

Permalink
updated nits
Browse files Browse the repository at this point in the history
  • Loading branch information
killianmuldoon committed Feb 8, 2022
1 parent 39ad602 commit d94cd51
Show file tree
Hide file tree
Showing 2 changed files with 97 additions and 347 deletions.
79 changes: 0 additions & 79 deletions internal/webhooks/clusterclass_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2383,82 +2383,3 @@ func TestClusterClassValidationWithVariableChecks(t *testing.T) {
})
}
}

func TestClusterClass_ValidateDelete(t *testing.T) {
class := builder.ClusterClass(metav1.NamespaceDefault, "class1").Build()

tests := []struct {
name string
clusters []client.Object
expectErr bool
}{

{
name: "error if cluster exists with a reference to the ClusterClass for deletion",
clusters: []client.Object{
builder.Cluster(metav1.NamespaceDefault, "cluster1").
WithLabels(map[string]string{clusterv1.ClusterTopologyOwnedLabel: ""}).
WithTopology(
builder.ClusterTopology().
WithClass("class1").
Build()).
Build(),
},
expectErr: true,
},
{
name: "error if multiple clusters exist and at least one references to the ClusterClass for deletion",
clusters: []client.Object{
builder.Cluster(metav1.NamespaceDefault, "cluster1").
WithLabels(map[string]string{clusterv1.ClusterTopologyOwnedLabel: ""}).
WithTopology(
builder.ClusterTopology().
WithClass("class1").
Build()).
Build(),
builder.Cluster(metav1.NamespaceDefault, "cluster2").
WithLabels(map[string]string{clusterv1.ClusterTopologyOwnedLabel: ""}).
WithTopology(
builder.ClusterTopology().
WithClass("class2").
Build()).
Build(),
builder.Cluster(metav1.NamespaceDefault, "cluster3").
WithLabels(map[string]string{clusterv1.ClusterTopologyOwnedLabel: ""}).
WithTopology(
builder.ClusterTopology().
WithClass("class3").
Build()).
Build(),
builder.Cluster(metav1.NamespaceDefault, "cluster4").
WithLabels(map[string]string{clusterv1.ClusterTopologyOwnedLabel: ""}).
WithTopology(
builder.ClusterTopology().
WithClass("class4").
Build()).
Build(),
},
expectErr: true,
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
g := NewWithT(t)
// Sets up the fakeClient for the test case.
fakeClient := fake.NewClientBuilder().
WithObjects(tt.clusters...).
WithScheme(fakeScheme).
Build()

// Create the webhook and add the fakeClient as its client.
webhook := &ClusterClass{Client: fakeClient}
err := webhook.ValidateDelete(ctx, class)
if tt.expectErr {
g.Expect(err).To(HaveOccurred())
return
}
g.Expect(err).ToNot(HaveOccurred())
})
}
}
Loading

0 comments on commit d94cd51

Please sign in to comment.