Skip to content

Commit e64e069

Browse files
authored
Merge pull request #5622 from killianmuldoon/test/add-builders-to-webhook-tests
🌱 Use internal/builders in tests for webhook package
2 parents 79b1f98 + 87afe7f commit e64e069

File tree

10 files changed

+963
-1536
lines changed

10 files changed

+963
-1536
lines changed

cmd/clusterctl/internal/test/fake_objects.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1458,7 +1458,7 @@ func (f *FakeClusterClass) Objs() []client.Object {
14581458
objMap[fakeMDClass.bootstrapTemplate] = true
14591459
objMap[fakeMDClass.infrastructureTemplate] = true
14601460
}
1461-
clusterClassBuilder.WithWorkerMachineDeploymentClasses(mdClasses)
1461+
clusterClassBuilder.WithWorkerMachineDeploymentClasses(mdClasses...)
14621462
}
14631463

14641464
clusterClass := clusterClassBuilder.Build()

controllers/topology/blueprint_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ func TestGetBlueprint(t *testing.T) {
182182
clusterClass: builder.ClusterClass(metav1.NamespaceDefault, "class1").
183183
WithInfrastructureClusterTemplate(infraClusterTemplate).
184184
WithControlPlaneTemplate(controlPlaneTemplate).
185-
WithWorkerMachineDeploymentClasses(mds).
185+
WithWorkerMachineDeploymentClasses(mds...).
186186
Build(),
187187
objects: []client.Object{
188188
infraClusterTemplate,
@@ -194,7 +194,7 @@ func TestGetBlueprint(t *testing.T) {
194194
ClusterClass: builder.ClusterClass(metav1.NamespaceDefault, "class1").
195195
WithInfrastructureClusterTemplate(infraClusterTemplate).
196196
WithControlPlaneTemplate(controlPlaneTemplate).
197-
WithWorkerMachineDeploymentClasses(mds).
197+
WithWorkerMachineDeploymentClasses(mds...).
198198
Build(),
199199
InfrastructureClusterTemplate: infraClusterTemplate,
200200
ControlPlane: &scope.ControlPlaneBlueprint{
@@ -217,7 +217,7 @@ func TestGetBlueprint(t *testing.T) {
217217
clusterClass: builder.ClusterClass(metav1.NamespaceDefault, "class1").
218218
WithInfrastructureClusterTemplate(infraClusterTemplate).
219219
WithControlPlaneTemplate(controlPlaneTemplate).
220-
WithWorkerMachineDeploymentClasses(mds).
220+
WithWorkerMachineDeploymentClasses(mds...).
221221
Build(),
222222
objects: []client.Object{
223223
infraClusterTemplate,
@@ -232,7 +232,7 @@ func TestGetBlueprint(t *testing.T) {
232232
clusterClass: builder.ClusterClass(metav1.NamespaceDefault, "class1").
233233
WithInfrastructureClusterTemplate(infraClusterTemplate).
234234
WithControlPlaneTemplate(controlPlaneTemplate).
235-
WithWorkerMachineDeploymentClasses(mds).
235+
WithWorkerMachineDeploymentClasses(mds...).
236236
Build(),
237237
objects: []client.Object{
238238
infraClusterTemplate,

controllers/topology/cluster_controller_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ func setupTestEnvForIntegrationTests(ns *corev1.Namespace) (func() error, error)
325325
WithInfrastructureClusterTemplate(infrastructureClusterTemplate).
326326
WithControlPlaneTemplate(controlPlaneTemplate).
327327
WithControlPlaneInfrastructureMachineTemplate(infrastructureMachineTemplate).
328-
WithWorkerMachineDeploymentClasses([]clusterv1.MachineDeploymentClass{*machineDeploymentClass1, *machineDeploymentClass2}).
328+
WithWorkerMachineDeploymentClasses(*machineDeploymentClass1, *machineDeploymentClass2).
329329
Build()
330330

331331
// 3) Two Clusters including a Cluster Topology objects and the MachineDeploymentTopology objects used in the

controllers/topology/clusterclass_controller_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ func TestClusterClassReconciler_reconcile(t *testing.T) {
7676
WithInfrastructureClusterTemplate(infraClusterTemplate).
7777
WithControlPlaneTemplate(controlPlaneTemplate).
7878
WithControlPlaneInfrastructureMachineTemplate(infraMachineTemplateControlPlane).
79-
WithWorkerMachineDeploymentClasses([]clusterv1.MachineDeploymentClass{*machineDeploymentClass1, *machineDeploymentClass2}).
79+
WithWorkerMachineDeploymentClasses(*machineDeploymentClass1, *machineDeploymentClass2).
8080
Build()
8181

8282
// Create the set of initObjects from the objects above to add to the API server when the test environment starts.

controllers/topology/desired_state_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -688,7 +688,7 @@ func TestComputeMachineDeployment(t *testing.T) {
688688
Build()
689689
mcds := []clusterv1.MachineDeploymentClass{*md1}
690690
fakeClass := builder.ClusterClass(metav1.NamespaceDefault, "class1").
691-
WithWorkerMachineDeploymentClasses(mcds).
691+
WithWorkerMachineDeploymentClasses(mcds...).
692692
Build()
693693

694694
version := "v1.21.2"

controllers/topology/internal/extensions/patches/engine_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -466,7 +466,7 @@ func setupTestObjects() (*scope.ClusterBlueprint, *scope.ClusterState) {
466466
WithInfrastructureClusterTemplate(infrastructureClusterTemplate).
467467
WithControlPlaneTemplate(controlPlaneTemplate).
468468
WithControlPlaneInfrastructureMachineTemplate(controlPlaneInfrastructureMachineTemplate).
469-
WithWorkerMachineDeploymentClasses([]clusterv1.MachineDeploymentClass{*mdClass1}).
469+
WithWorkerMachineDeploymentClasses(*mdClass1).
470470
Build()
471471

472472
cluster := &clusterv1.Cluster{

internal/builder/builders.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ func (c *ClusterClassBuilder) WithControlPlaneInfrastructureMachineTemplate(t *u
219219
}
220220

221221
// WithWorkerMachineDeploymentClasses adds the variables and objects needed to create MachineDeploymentTemplates for a ClusterClassBuilder.
222-
func (c *ClusterClassBuilder) WithWorkerMachineDeploymentClasses(mdcs []clusterv1.MachineDeploymentClass) *ClusterClassBuilder {
222+
func (c *ClusterClassBuilder) WithWorkerMachineDeploymentClasses(mdcs ...clusterv1.MachineDeploymentClass) *ClusterClassBuilder {
223223
if c.machineDeploymentClasses == nil {
224224
c.machineDeploymentClasses = make([]clusterv1.MachineDeploymentClass, 0)
225225
}

webhooks/cluster.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ func (webhook *Cluster) validateTopology(ctx context.Context, old, new *clusterv
252252
allErrs = append(
253253
allErrs, field.Invalid(
254254
field.NewPath("spec", "topology", "class"),
255-
new.Name,
255+
new.Spec.Topology.Class,
256256
"ClusterClass could not be found"))
257257
}
258258
return allErrs

0 commit comments

Comments
 (0)