@@ -33,24 +33,26 @@ func (m *mockCheck) Run(ctx context.Context) preflight.CheckResult {
3333
3434func TestNutanixChecker_Init (t * testing.T ) {
3535 tests := []struct {
36- name string
37- nutanixConfig * carenv1.NutanixClusterConfigSpec
38- workerNodeConfigs map [string ]* carenv1.NutanixWorkerNodeConfigSpec
39- expectedCheckCount int
40- expectedFirstCheckName string
41- expectedSecondCheckName string
42- vmImageCheckCount int
43- storageContainerCheckCount int
36+ name string
37+ nutanixConfig * carenv1.NutanixClusterConfigSpec
38+ workerNodeConfigs map [string ]* carenv1.NutanixWorkerNodeConfigSpec
39+ expectedCheckCount int
40+ expectedFirstCheckName string
41+ expectedSecondCheckName string
42+ vmImageCheckCount int
43+ vmImageKubernetesVersionCheckCount int
44+ storageContainerCheckCount int
4445 }{
4546 {
46- name : "basic initialization with no configs" ,
47- nutanixConfig : nil ,
48- workerNodeConfigs : nil ,
49- expectedCheckCount : 2 , // config check and credentials check
50- expectedFirstCheckName : "NutanixConfiguration" ,
51- expectedSecondCheckName : "NutanixCredentials" ,
52- vmImageCheckCount : 0 ,
53- storageContainerCheckCount : 0 ,
47+ name : "basic initialization with no configs" ,
48+ nutanixConfig : nil ,
49+ workerNodeConfigs : nil ,
50+ expectedCheckCount : 2 , // config check and credentials check
51+ expectedFirstCheckName : "NutanixConfiguration" ,
52+ expectedSecondCheckName : "NutanixCredentials" ,
53+ vmImageCheckCount : 0 ,
54+ vmImageKubernetesVersionCheckCount : 0 ,
55+ storageContainerCheckCount : 0 ,
5456 },
5557 {
5658 name : "initialization with control plane config" ,
@@ -59,12 +61,13 @@ func TestNutanixChecker_Init(t *testing.T) {
5961 Nutanix : & carenv1.NutanixNodeSpec {},
6062 },
6163 },
62- workerNodeConfigs : nil ,
63- expectedCheckCount : 4 , // config check, credentials check, 1 VM image check, 1 storage container check
64- expectedFirstCheckName : "NutanixConfiguration" ,
65- expectedSecondCheckName : "NutanixCredentials" ,
66- vmImageCheckCount : 1 ,
67- storageContainerCheckCount : 1 ,
64+ workerNodeConfigs : nil ,
65+ expectedCheckCount : 5 , //nolint:lll // config check, credentials check, 1 VM image check, 1 storage container check, 1 VM image Kubernetes version check
66+ expectedFirstCheckName : "NutanixConfiguration" ,
67+ expectedSecondCheckName : "NutanixCredentials" ,
68+ vmImageCheckCount : 1 ,
69+ vmImageKubernetesVersionCheckCount : 1 ,
70+ storageContainerCheckCount : 1 ,
6871 },
6972 {
7073 name : "initialization with worker node configs" ,
@@ -77,11 +80,12 @@ func TestNutanixChecker_Init(t *testing.T) {
7780 Nutanix : & carenv1.NutanixNodeSpec {},
7881 },
7982 },
80- expectedCheckCount : 6 , // config check, credentials check, 2 VM image checks, 2 storage container checks
81- expectedFirstCheckName : "NutanixConfiguration" ,
82- expectedSecondCheckName : "NutanixCredentials" ,
83- vmImageCheckCount : 2 ,
84- storageContainerCheckCount : 2 ,
83+ expectedCheckCount : 8 , //nolint:lll // config check, credentials check, 2 VM image checks, 2 storage container checks, 2 VM image Kubernetes version checks
84+ expectedFirstCheckName : "NutanixConfiguration" ,
85+ expectedSecondCheckName : "NutanixCredentials" ,
86+ vmImageCheckCount : 2 ,
87+ vmImageKubernetesVersionCheckCount : 2 ,
88+ storageContainerCheckCount : 2 ,
8589 },
8690 {
8791 name : "initialization with both control plane and worker node configs" ,
@@ -95,12 +99,12 @@ func TestNutanixChecker_Init(t *testing.T) {
9599 Nutanix : & carenv1.NutanixNodeSpec {},
96100 },
97101 },
98- // config check, credentials check, 2 VM image checks (1 CP + 1 worker), 2 storage container checks (1 CP + 1 worker)
99- expectedCheckCount : 6 ,
100- expectedFirstCheckName : "NutanixConfiguration " ,
101- expectedSecondCheckName : "NutanixCredentials" ,
102- vmImageCheckCount : 2 ,
103- storageContainerCheckCount : 2 ,
102+ expectedCheckCount : 8 , //nolint:lll // config check, credentials check, 2 VM image checks (1 CP + 1 worker), 2 storage container checks (1 CP + 1 worker), 2 VM image Kubernetes version checks
103+ expectedFirstCheckName : "NutanixConfiguration" ,
104+ expectedSecondCheckName : "NutanixCredentials " ,
105+ vmImageCheckCount : 2 ,
106+ vmImageKubernetesVersionCheckCount : 2 ,
107+ storageContainerCheckCount : 2 ,
104108 },
105109 }
106110
@@ -114,6 +118,7 @@ func TestNutanixChecker_Init(t *testing.T) {
114118 credsCheckCalled := false
115119 vmImageCheckCount := 0
116120 storageContainerCheckCount := 0
121+ vmImageKubernetesVersionCheckCount := 0
117122
118123 checker .configurationCheckFactory = func (cd * checkDependencies ) preflight.Check {
119124 configCheckCalled = true
@@ -167,6 +172,22 @@ func TestNutanixChecker_Init(t *testing.T) {
167172 return checks
168173 }
169174
175+ checker .vmImageKubernetesVersionChecksFactory = func (cd * checkDependencies ) []preflight.Check {
176+ checks := []preflight.Check {}
177+ for i := 0 ; i < tt .vmImageKubernetesVersionCheckCount ; i ++ {
178+ vmImageKubernetesVersionCheckCount ++
179+ checks = append (checks ,
180+ & mockCheck {
181+ name : fmt .Sprintf ("NutanixVMImageKubernetesVersion-%d" , i ),
182+ result : preflight.CheckResult {
183+ Allowed : true ,
184+ },
185+ },
186+ )
187+ }
188+ return checks
189+ }
190+
170191 // Call Init
171192 ctx := context .Background ()
172193 checks := checker .Init (ctx , nil , & clusterv1.Cluster {
0 commit comments