Skip to content

Commit 3034ef7

Browse files
committed
refactor: nutanix variables test
1 parent b68012a commit 3034ef7

File tree

1 file changed

+61
-95
lines changed

1 file changed

+61
-95
lines changed

pkg/handlers/nutanix/mutation/machinedetails/variables_test.go

Lines changed: 61 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -17,121 +17,87 @@ import (
1717
)
1818

1919
func TestVariableValidation(t *testing.T) {
20-
testImageName := "fake-image"
21-
testPEClusterName := "fake-pe-cluster"
22-
testProject := ptr.To(v1alpha1.NutanixResourceIdentifier{
20+
requiredFields := minimumClusterConfigSpec()
21+
22+
withProject := minimumClusterConfigSpec()
23+
withProject.ControlPlane.Nutanix.MachineDetails.Project = ptr.To(v1alpha1.NutanixResourceIdentifier{
2324
Type: capxv1.NutanixIdentifierName,
2425
Name: ptr.To("fake-project"),
2526
})
27+
28+
invalidBootType := minimumClusterConfigSpec()
29+
invalidBootType.ControlPlane.Nutanix.MachineDetails.BootType = "invalid-boot-type"
30+
31+
invalidImageType := minimumClusterConfigSpec()
32+
invalidImageType.ControlPlane.Nutanix.MachineDetails.Image.Type = "invalid-image-type"
33+
34+
invalidClusterType := minimumClusterConfigSpec()
35+
invalidClusterType.ControlPlane.Nutanix.MachineDetails.Cluster.Type = "invalid-cluster-type"
36+
37+
invalidProjectType := minimumClusterConfigSpec()
38+
invalidProjectType.ControlPlane.Nutanix.MachineDetails.Project = ptr.To(v1alpha1.NutanixResourceIdentifier{
39+
Type: "invalid-project-type",
40+
Name: ptr.To("fake-project"),
41+
})
42+
2643
capitest.ValidateDiscoverVariables(
2744
t,
2845
clusterconfig.MetaVariableName,
2946
ptr.To(v1alpha1.ClusterConfigSpec{Nutanix: &v1alpha1.NutanixSpec{}}.VariableSchema()),
3047
true,
3148
nutanixclusterconfig.NewVariable,
3249
capitest.VariableTestDef{
33-
Name: "all fields set",
34-
Vals: v1alpha1.ClusterConfigSpec{
35-
ControlPlane: &v1alpha1.NodeConfigSpec{
36-
Nutanix: &v1alpha1.NutanixNodeSpec{
37-
MachineDetails: v1alpha1.NutanixMachineDetails{
38-
BootType: v1alpha1.NutanixBootType(capxv1.NutanixBootTypeLegacy),
39-
VCPUSockets: 2,
40-
VCPUsPerSocket: 1,
41-
Image: v1alpha1.NutanixResourceIdentifier{
42-
Type: capxv1.NutanixIdentifierName,
43-
Name: &testImageName,
44-
},
45-
Cluster: v1alpha1.NutanixResourceIdentifier{
46-
Type: capxv1.NutanixIdentifierName,
47-
Name: &testPEClusterName,
48-
},
49-
MemorySize: resource.MustParse("8Gi"),
50-
Project: testProject,
51-
SystemDiskSize: resource.MustParse("40Gi"),
52-
Subnets: []v1alpha1.NutanixResourceIdentifier{},
53-
},
54-
},
55-
},
56-
},
50+
Name: "required fields set",
51+
Vals: requiredFields,
5752
},
5853
capitest.VariableTestDef{
59-
Name: "invalid boot type",
60-
Vals: v1alpha1.ClusterConfigSpec{
61-
ControlPlane: &v1alpha1.NodeConfigSpec{
62-
Nutanix: &v1alpha1.NutanixNodeSpec{
63-
MachineDetails: v1alpha1.NutanixMachineDetails{
64-
BootType: "invalid",
65-
VCPUSockets: 2,
66-
VCPUsPerSocket: 1,
67-
Image: v1alpha1.NutanixResourceIdentifier{
68-
Type: capxv1.NutanixIdentifierName,
69-
Name: &testImageName,
70-
},
71-
Cluster: v1alpha1.NutanixResourceIdentifier{
72-
Type: capxv1.NutanixIdentifierName,
73-
Name: &testPEClusterName,
74-
},
75-
MemorySize: resource.MustParse("8Gi"),
76-
SystemDiskSize: resource.MustParse("40Gi"),
77-
Subnets: []v1alpha1.NutanixResourceIdentifier{},
78-
},
79-
},
80-
},
81-
},
54+
Name: "project set",
55+
Vals: withProject,
56+
},
57+
capitest.VariableTestDef{
58+
Name: "invalid boot type",
59+
Vals: invalidBootType,
8260
ExpectError: true,
8361
},
8462
capitest.VariableTestDef{
85-
Name: "invalid image type",
86-
Vals: v1alpha1.ClusterConfigSpec{
87-
ControlPlane: &v1alpha1.NodeConfigSpec{
88-
Nutanix: &v1alpha1.NutanixNodeSpec{
89-
MachineDetails: v1alpha1.NutanixMachineDetails{
90-
BootType: v1alpha1.NutanixBootType(capxv1.NutanixBootTypeLegacy),
91-
VCPUSockets: 2,
92-
VCPUsPerSocket: 1,
93-
Image: v1alpha1.NutanixResourceIdentifier{
94-
Type: "invalid",
95-
Name: &testImageName,
96-
},
97-
Cluster: v1alpha1.NutanixResourceIdentifier{
98-
Type: capxv1.NutanixIdentifierName,
99-
Name: &testPEClusterName,
100-
},
101-
MemorySize: resource.MustParse("8Gi"),
102-
SystemDiskSize: resource.MustParse("40Gi"),
103-
Subnets: []v1alpha1.NutanixResourceIdentifier{},
104-
},
105-
},
106-
},
107-
},
63+
Name: "invalid image type",
64+
Vals: invalidImageType,
10865
ExpectError: true,
10966
},
11067
capitest.VariableTestDef{
111-
Name: "invalid cluster type",
112-
Vals: v1alpha1.ClusterConfigSpec{
113-
ControlPlane: &v1alpha1.NodeConfigSpec{
114-
Nutanix: &v1alpha1.NutanixNodeSpec{
115-
MachineDetails: v1alpha1.NutanixMachineDetails{
116-
BootType: v1alpha1.NutanixBootType(capxv1.NutanixBootTypeLegacy),
117-
VCPUSockets: 2,
118-
VCPUsPerSocket: 1,
119-
Image: v1alpha1.NutanixResourceIdentifier{
120-
Type: capxv1.NutanixIdentifierName,
121-
Name: &testImageName,
122-
},
123-
Cluster: v1alpha1.NutanixResourceIdentifier{
124-
Type: "invalid",
125-
Name: &testPEClusterName,
126-
},
127-
MemorySize: resource.MustParse("8Gi"),
128-
SystemDiskSize: resource.MustParse("40Gi"),
129-
Subnets: []v1alpha1.NutanixResourceIdentifier{},
130-
},
68+
Name: "invalid cluster type",
69+
Vals: invalidClusterType,
70+
ExpectError: true,
71+
},
72+
capitest.VariableTestDef{
73+
Name: "invalid project type",
74+
Vals: invalidProjectType,
75+
ExpectError: true,
76+
},
77+
)
78+
}
79+
80+
func minimumClusterConfigSpec() v1alpha1.ClusterConfigSpec {
81+
return v1alpha1.ClusterConfigSpec{
82+
ControlPlane: &v1alpha1.NodeConfigSpec{
83+
Nutanix: &v1alpha1.NutanixNodeSpec{
84+
MachineDetails: v1alpha1.NutanixMachineDetails{
85+
BootType: v1alpha1.NutanixBootType(capxv1.NutanixBootTypeLegacy),
86+
VCPUSockets: 2,
87+
VCPUsPerSocket: 1,
88+
Image: v1alpha1.NutanixResourceIdentifier{
89+
Type: capxv1.NutanixIdentifierName,
90+
Name: ptr.To("fake-image"),
13191
},
92+
Cluster: v1alpha1.NutanixResourceIdentifier{
93+
Type: capxv1.NutanixIdentifierName,
94+
Name: ptr.To("fake-pe-cluster"),
95+
},
96+
MemorySize: resource.MustParse("8Gi"),
97+
SystemDiskSize: resource.MustParse("40Gi"),
98+
Subnets: []v1alpha1.NutanixResourceIdentifier{},
13299
},
133100
},
134-
ExpectError: true,
135101
},
136-
)
102+
}
137103
}

0 commit comments

Comments
 (0)