Skip to content

Commit e076a1d

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

File tree

1 file changed

+85
-108
lines changed

1 file changed

+85
-108
lines changed

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

Lines changed: 85 additions & 108 deletions
Original file line numberDiff line numberDiff line change
@@ -17,131 +17,108 @@ import (
1717
)
1818

1919
func TestVariableValidation(t *testing.T) {
20-
testImageName := "fake-image"
21-
testPEClusterName := "fake-pe-cluster"
22-
testProject := ptr.To(v1alpha1.NutanixResourceIdentifier{
23-
Type: capxv1.NutanixIdentifierName,
24-
Name: ptr.To("fake-project"),
25-
})
20+
requiredFields := minimumClusterConfigSpec()
21+
22+
withAdditionalCategories := minimumClusterConfigSpec()
23+
//nolint:lll // gofumpt formats is this way
24+
withAdditionalCategories.ControlPlane.Nutanix.MachineDetails.AdditionalCategories = []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(
37+
v1alpha1.NutanixResourceIdentifier{
38+
Type: capxv1.NutanixIdentifierName,
39+
Name: ptr.To("fake-project"),
40+
},
41+
)
42+
43+
invalidBootType := minimumClusterConfigSpec()
44+
invalidBootType.ControlPlane.Nutanix.MachineDetails.BootType = "invalid-boot-type"
45+
46+
invalidImageType := minimumClusterConfigSpec()
47+
invalidImageType.ControlPlane.Nutanix.MachineDetails.Image.Type = "invalid-image-type"
48+
49+
invalidClusterType := minimumClusterConfigSpec()
50+
invalidClusterType.ControlPlane.Nutanix.MachineDetails.Cluster.Type = "invalid-cluster-type"
51+
52+
invalidProjectType := minimumClusterConfigSpec()
53+
invalidProjectType.ControlPlane.Nutanix.MachineDetails.Project = ptr.To(
54+
v1alpha1.NutanixResourceIdentifier{
55+
Type: "invalid-project-type",
56+
Name: ptr.To("fake-project"),
57+
},
58+
)
59+
2660
capitest.ValidateDiscoverVariables(
2761
t,
2862
clusterconfig.MetaVariableName,
2963
ptr.To(v1alpha1.ClusterConfigSpec{Nutanix: &v1alpha1.NutanixSpec{}}.VariableSchema()),
3064
true,
3165
nutanixclusterconfig.NewVariable,
3266
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-
},
67+
Name: "required fields set",
68+
Vals: requiredFields,
6769
},
6870
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-
},
71+
Name: "additional categories set",
72+
Vals: withAdditionalCategories,
73+
},
74+
capitest.VariableTestDef{
75+
Name: "project set",
76+
Vals: withProject,
77+
},
78+
capitest.VariableTestDef{
79+
Name: "invalid boot type",
80+
Vals: invalidBootType,
9281
ExpectError: true,
9382
},
9483
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-
},
84+
Name: "invalid image type",
85+
Vals: invalidImageType,
86+
ExpectError: true,
87+
},
88+
capitest.VariableTestDef{
89+
Name: "invalid cluster type",
90+
Vals: invalidClusterType,
11891
ExpectError: true,
11992
},
12093
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-
},
94+
Name: "invalid project type",
95+
Vals: invalidProjectType,
96+
ExpectError: true,
97+
},
98+
)
99+
}
100+
101+
func minimumClusterConfigSpec() v1alpha1.ClusterConfigSpec {
102+
return v1alpha1.ClusterConfigSpec{
103+
ControlPlane: &v1alpha1.NodeConfigSpec{
104+
Nutanix: &v1alpha1.NutanixNodeSpec{
105+
MachineDetails: v1alpha1.NutanixMachineDetails{
106+
BootType: v1alpha1.NutanixBootType(capxv1.NutanixBootTypeLegacy),
107+
VCPUSockets: 2,
108+
VCPUsPerSocket: 1,
109+
Image: v1alpha1.NutanixResourceIdentifier{
110+
Type: capxv1.NutanixIdentifierName,
111+
Name: ptr.To("fake-image"),
112+
},
113+
Cluster: v1alpha1.NutanixResourceIdentifier{
114+
Type: capxv1.NutanixIdentifierName,
115+
Name: ptr.To("fake-pe-cluster"),
141116
},
117+
MemorySize: resource.MustParse("8Gi"),
118+
SystemDiskSize: resource.MustParse("40Gi"),
119+
Subnets: []v1alpha1.NutanixResourceIdentifier{},
142120
},
143121
},
144-
ExpectError: true,
145122
},
146-
)
123+
}
147124
}

0 commit comments

Comments
 (0)