Skip to content

Commit 5d654f8

Browse files
committed
ci: adds unit test for imagelookup feature
1 parent ef7b306 commit 5d654f8

File tree

3 files changed

+99
-14
lines changed

3 files changed

+99
-14
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,9 @@ func (h *nutanixMachineDetailsPatchHandler) Mutate(
9595
spec.BootType = nutanixMachineDetailsVar.BootType
9696
spec.Cluster = nutanixMachineDetailsVar.Cluster
9797
if nutanixMachineDetailsVar.Image != nil {
98-
spec.Image = nutanixMachineDetailsVar.Image
98+
spec.Image = nutanixMachineDetailsVar.Image.DeepCopy()
9999
} else if nutanixMachineDetailsVar.ImageLookup != nil {
100-
spec.ImageLookup = nutanixMachineDetailsVar.ImageLookup
100+
spec.ImageLookup = nutanixMachineDetailsVar.ImageLookup.DeepCopy()
101101
}
102102

103103
spec.VCPUSockets = nutanixMachineDetailsVar.VCPUSockets

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

Lines changed: 96 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ var (
2323
BootType: capxv1.NutanixBootTypeLegacy,
2424
VCPUSockets: 2,
2525
VCPUsPerSocket: 1,
26-
Image: capxv1.NutanixResourceIdentifier{
26+
Image: &capxv1.NutanixResourceIdentifier{
2727
Type: capxv1.NutanixIdentifierName,
2828
Name: ptr.To("fake-image"),
2929
},
@@ -65,6 +65,79 @@ var (
6565
},
6666
}
6767

68+
variableWithImageTemplating = v1alpha1.NutanixMachineDetails{
69+
BootType: capxv1.NutanixBootTypeLegacy,
70+
VCPUSockets: 2,
71+
VCPUsPerSocket: 1,
72+
ImageLookup: &capxv1.NutanixImageLookup{
73+
BaseOS: "rockylinux-9",
74+
},
75+
Cluster: capxv1.NutanixResourceIdentifier{
76+
Type: capxv1.NutanixIdentifierName,
77+
Name: ptr.To("fake-pe-cluster"),
78+
},
79+
MemorySize: resource.MustParse("8Gi"),
80+
SystemDiskSize: resource.MustParse("40Gi"),
81+
Subnets: []capxv1.NutanixResourceIdentifier{
82+
{
83+
Type: capxv1.NutanixIdentifierName,
84+
Name: ptr.To("fake-subnet"),
85+
},
86+
},
87+
}
88+
matchersForAllImageTemplating = []capitest.JSONPatchMatcher{
89+
// boot type
90+
{
91+
Operation: "add",
92+
Path: "/spec/template/spec/bootType",
93+
ValueMatcher: gomega.BeEquivalentTo(capxv1.NutanixBootTypeLegacy),
94+
},
95+
// cluster
96+
{
97+
Operation: "add",
98+
Path: "/spec/template/spec/cluster/name",
99+
ValueMatcher: gomega.BeEquivalentTo("fake-pe-cluster"),
100+
},
101+
{
102+
Operation: "replace",
103+
Path: "/spec/template/spec/cluster/type",
104+
ValueMatcher: gomega.BeEquivalentTo(capxv1.NutanixIdentifierName),
105+
},
106+
107+
{
108+
Operation: "replace",
109+
Path: "/spec/template/spec/vcpuSockets",
110+
ValueMatcher: gomega.BeEquivalentTo(2),
111+
},
112+
{
113+
Operation: "replace",
114+
Path: "/spec/template/spec/vcpusPerSocket",
115+
ValueMatcher: gomega.BeEquivalentTo(1),
116+
},
117+
{
118+
Operation: "replace",
119+
Path: "/spec/template/spec/memorySize",
120+
ValueMatcher: gomega.BeEquivalentTo("8Gi"),
121+
},
122+
{
123+
Operation: "replace",
124+
Path: "/spec/template/spec/systemDiskSize",
125+
ValueMatcher: gomega.BeEquivalentTo("40Gi"),
126+
},
127+
{
128+
Operation: "replace",
129+
Path: "/spec/template/spec/subnet",
130+
ValueMatcher: gomega.HaveLen(1),
131+
},
132+
{
133+
Operation: "add",
134+
Path: "/spec/template/spec/imageLookup",
135+
ValueMatcher: gomega.SatisfyAll(
136+
gomega.HaveKeyWithValue("baseOS", "rockylinux-9"),
137+
),
138+
},
139+
}
140+
68141
matchersForAllFieldsSet = []capitest.JSONPatchMatcher{
69142
{
70143
Operation: "add",
@@ -85,16 +158,6 @@ var (
85158
Path: "/spec/template/spec/bootType",
86159
ValueMatcher: gomega.BeEquivalentTo(capxv1.NutanixBootTypeLegacy),
87160
},
88-
{
89-
Operation: "add",
90-
Path: "/spec/template/spec/image/name",
91-
ValueMatcher: gomega.BeEquivalentTo("fake-image"),
92-
},
93-
{
94-
Operation: "replace",
95-
Path: "/spec/template/spec/image/type",
96-
ValueMatcher: gomega.BeEquivalentTo(capxv1.NutanixIdentifierName),
97-
},
98161
{
99162
Operation: "add",
100163
Path: "/spec/template/spec/cluster/name",
@@ -130,6 +193,14 @@ var (
130193
Path: "/spec/template/spec/subnet",
131194
ValueMatcher: gomega.HaveLen(1),
132195
},
196+
{
197+
Operation: "add",
198+
Path: "/spec/template/spec/image",
199+
ValueMatcher: gomega.SatisfyAll(
200+
gomega.HaveKeyWithValue("type", "name"),
201+
gomega.HaveKeyWithValue("name", "fake-image"),
202+
),
203+
},
133204
{
134205
Operation: "add",
135206
Path: "/spec/template/spec/additionalCategories",
@@ -182,6 +253,20 @@ var _ = Describe("Generate Nutanix Machine Details patches for ControlPlane", fu
182253
RequestItem: request.NewCPNutanixMachineTemplateRequestItem(""),
183254
ExpectedPatchMatchers: matchersForAllFieldsSet,
184255
},
256+
{
257+
Name: "image templating set for control-plane",
258+
Vars: []runtimehooksv1.Variable{
259+
capitest.VariableWithValue(
260+
v1alpha1.ClusterConfigVariableName,
261+
variableWithImageTemplating,
262+
v1alpha1.ControlPlaneConfigVariableName,
263+
v1alpha1.NutanixVariableName,
264+
VariableName,
265+
),
266+
},
267+
RequestItem: request.NewCPNutanixMachineTemplateRequestItem(""),
268+
ExpectedPatchMatchers: matchersForAllImageTemplating,
269+
},
185270
}
186271

187272
// create test node for each case

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ func minimumClusterConfigSpec() v1alpha1.NutanixClusterConfigSpec {
105105
BootType: capxv1.NutanixBootTypeLegacy,
106106
VCPUSockets: 2,
107107
VCPUsPerSocket: 1,
108-
Image: capxv1.NutanixResourceIdentifier{
108+
Image: &capxv1.NutanixResourceIdentifier{
109109
Type: capxv1.NutanixIdentifierName,
110110
Name: ptr.To("fake-image"),
111111
},

0 commit comments

Comments
 (0)