Skip to content

Commit 11e4105

Browse files
committed
refactor: nutanix variables test
1 parent f529289 commit 11e4105

File tree

1 file changed

+78
-105
lines changed

1 file changed

+78
-105
lines changed

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

Lines changed: 78 additions & 105 deletions
Original file line numberDiff line numberDiff line change
@@ -17,131 +17,104 @@ 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+
withAdditionalCategories := minimumClusterConfigSpec()
23+
withAdditionalCategories.ControlPlane.Nutanix.MachineDetails.AdditionalCategories =
24+
[]v1alpha1.NutanixCategoryIdentifier{
25+
{
26+
Key: "fake-key",
27+
Value: "fake-value1",
28+
},
29+
{
30+
Key: "fake-key",
31+
Value: "fake-value2",
32+
},
33+
}
34+
35+
withProject := minimumClusterConfigSpec()
36+
withProject.ControlPlane.Nutanix.MachineDetails.Project = ptr.To(v1alpha1.NutanixResourceIdentifier{
2337
Type: capxv1.NutanixIdentifierName,
2438
Name: ptr.To("fake-project"),
2539
})
40+
41+
invalidBootType := minimumClusterConfigSpec()
42+
invalidBootType.ControlPlane.Nutanix.MachineDetails.BootType = "invalid-boot-type"
43+
44+
invalidImageType := minimumClusterConfigSpec()
45+
invalidImageType.ControlPlane.Nutanix.MachineDetails.Image.Type = "invalid-image-type"
46+
47+
invalidClusterType := minimumClusterConfigSpec()
48+
invalidClusterType.ControlPlane.Nutanix.MachineDetails.Cluster.Type = "invalid-cluster-type"
49+
50+
invalidProjectType := minimumClusterConfigSpec()
51+
invalidProjectType.ControlPlane.Nutanix.MachineDetails.Project = ptr.To(v1alpha1.NutanixResourceIdentifier{
52+
Type: "invalid-project-type",
53+
Name: ptr.To("fake-project"),
54+
})
55+
2656
capitest.ValidateDiscoverVariables(
2757
t,
2858
clusterconfig.MetaVariableName,
2959
ptr.To(v1alpha1.ClusterConfigSpec{Nutanix: &v1alpha1.NutanixSpec{}}.VariableSchema()),
3060
true,
3161
nutanixclusterconfig.NewVariable,
3262
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-
AdditionalCategories: []v1alpha1.NutanixCategoryIdentifier{
54-
{
55-
Key: "fake-key",
56-
Value: "fake-value1",
57-
},
58-
{
59-
Key: "fake-key",
60-
Value: "fake-value2",
61-
},
62-
},
63-
},
64-
},
65-
},
66-
},
63+
Name: "required fields set",
64+
Vals: requiredFields,
6765
},
6866
capitest.VariableTestDef{
69-
Name: "invalid boot type",
70-
Vals: v1alpha1.ClusterConfigSpec{
71-
ControlPlane: &v1alpha1.NodeConfigSpec{
72-
Nutanix: &v1alpha1.NutanixNodeSpec{
73-
MachineDetails: v1alpha1.NutanixMachineDetails{
74-
BootType: "invalid",
75-
VCPUSockets: 2,
76-
VCPUsPerSocket: 1,
77-
Image: v1alpha1.NutanixResourceIdentifier{
78-
Type: capxv1.NutanixIdentifierName,
79-
Name: &testImageName,
80-
},
81-
Cluster: v1alpha1.NutanixResourceIdentifier{
82-
Type: capxv1.NutanixIdentifierName,
83-
Name: &testPEClusterName,
84-
},
85-
MemorySize: resource.MustParse("8Gi"),
86-
SystemDiskSize: resource.MustParse("40Gi"),
87-
Subnets: []v1alpha1.NutanixResourceIdentifier{},
88-
},
89-
},
90-
},
91-
},
67+
Name: "additional categories set",
68+
Vals: withAdditionalCategories,
69+
},
70+
capitest.VariableTestDef{
71+
Name: "project set",
72+
Vals: withProject,
73+
},
74+
capitest.VariableTestDef{
75+
Name: "invalid boot type",
76+
Vals: invalidBootType,
9277
ExpectError: true,
9378
},
9479
capitest.VariableTestDef{
95-
Name: "invalid image type",
96-
Vals: v1alpha1.ClusterConfigSpec{
97-
ControlPlane: &v1alpha1.NodeConfigSpec{
98-
Nutanix: &v1alpha1.NutanixNodeSpec{
99-
MachineDetails: v1alpha1.NutanixMachineDetails{
100-
BootType: v1alpha1.NutanixBootType(capxv1.NutanixBootTypeLegacy),
101-
VCPUSockets: 2,
102-
VCPUsPerSocket: 1,
103-
Image: v1alpha1.NutanixResourceIdentifier{
104-
Type: "invalid",
105-
Name: &testImageName,
106-
},
107-
Cluster: v1alpha1.NutanixResourceIdentifier{
108-
Type: capxv1.NutanixIdentifierName,
109-
Name: &testPEClusterName,
110-
},
111-
MemorySize: resource.MustParse("8Gi"),
112-
SystemDiskSize: resource.MustParse("40Gi"),
113-
Subnets: []v1alpha1.NutanixResourceIdentifier{},
114-
},
115-
},
116-
},
117-
},
80+
Name: "invalid image type",
81+
Vals: invalidImageType,
82+
ExpectError: true,
83+
},
84+
capitest.VariableTestDef{
85+
Name: "invalid cluster type",
86+
Vals: invalidClusterType,
11887
ExpectError: true,
11988
},
12089
capitest.VariableTestDef{
121-
Name: "invalid cluster type",
122-
Vals: v1alpha1.ClusterConfigSpec{
123-
ControlPlane: &v1alpha1.NodeConfigSpec{
124-
Nutanix: &v1alpha1.NutanixNodeSpec{
125-
MachineDetails: v1alpha1.NutanixMachineDetails{
126-
BootType: v1alpha1.NutanixBootType(capxv1.NutanixBootTypeLegacy),
127-
VCPUSockets: 2,
128-
VCPUsPerSocket: 1,
129-
Image: v1alpha1.NutanixResourceIdentifier{
130-
Type: capxv1.NutanixIdentifierName,
131-
Name: &testImageName,
132-
},
133-
Cluster: v1alpha1.NutanixResourceIdentifier{
134-
Type: "invalid",
135-
Name: &testPEClusterName,
136-
},
137-
MemorySize: resource.MustParse("8Gi"),
138-
SystemDiskSize: resource.MustParse("40Gi"),
139-
Subnets: []v1alpha1.NutanixResourceIdentifier{},
140-
},
90+
Name: "invalid project type",
91+
Vals: invalidProjectType,
92+
ExpectError: true,
93+
},
94+
)
95+
}
96+
97+
func minimumClusterConfigSpec() v1alpha1.ClusterConfigSpec {
98+
return v1alpha1.ClusterConfigSpec{
99+
ControlPlane: &v1alpha1.NodeConfigSpec{
100+
Nutanix: &v1alpha1.NutanixNodeSpec{
101+
MachineDetails: v1alpha1.NutanixMachineDetails{
102+
BootType: v1alpha1.NutanixBootType(capxv1.NutanixBootTypeLegacy),
103+
VCPUSockets: 2,
104+
VCPUsPerSocket: 1,
105+
Image: v1alpha1.NutanixResourceIdentifier{
106+
Type: capxv1.NutanixIdentifierName,
107+
Name: ptr.To("fake-image"),
108+
},
109+
Cluster: v1alpha1.NutanixResourceIdentifier{
110+
Type: capxv1.NutanixIdentifierName,
111+
Name: ptr.To("fake-pe-cluster"),
141112
},
113+
MemorySize: resource.MustParse("8Gi"),
114+
SystemDiskSize: resource.MustParse("40Gi"),
115+
Subnets: []v1alpha1.NutanixResourceIdentifier{},
142116
},
143117
},
144-
ExpectError: true,
145118
},
146-
)
119+
}
147120
}

0 commit comments

Comments
 (0)