@@ -33,22 +33,24 @@ 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
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
4344 }{
4445 {
45- name : "basic initialization with no configs" ,
46- nutanixConfig : nil ,
47- workerNodeConfigs : nil ,
48- expectedCheckCount : 2 , // config check and credentials check
49- expectedFirstCheckName : "NutanixConfiguration" ,
50- expectedSecondCheckName : "NutanixCredentials" ,
51- vmImageCheckCount : 0 ,
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 ,
5254 },
5355 {
5456 name : "initialization with control plane config" ,
@@ -57,11 +59,12 @@ func TestNutanixChecker_Init(t *testing.T) {
5759 Nutanix : & carenv1.NutanixNodeSpec {},
5860 },
5961 },
60- workerNodeConfigs : nil ,
61- expectedCheckCount : 3 , // config check, credentials check, 1 VM image check
62- expectedFirstCheckName : "NutanixConfiguration" ,
63- expectedSecondCheckName : "NutanixCredentials" ,
64- vmImageCheckCount : 1 ,
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 ,
6568 },
6669 {
6770 name : "initialization with worker node configs" ,
@@ -74,10 +77,11 @@ func TestNutanixChecker_Init(t *testing.T) {
7477 Nutanix : & carenv1.NutanixNodeSpec {},
7578 },
7679 },
77- expectedCheckCount : 4 , // config check, credentials check, 2 VM image checks
78- expectedFirstCheckName : "NutanixConfiguration" ,
79- expectedSecondCheckName : "NutanixCredentials" ,
80- vmImageCheckCount : 2 ,
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 ,
8185 },
8286 {
8387 name : "initialization with both control plane and worker node configs" ,
@@ -91,10 +95,12 @@ func TestNutanixChecker_Init(t *testing.T) {
9195 Nutanix : & carenv1.NutanixNodeSpec {},
9296 },
9397 },
94- expectedCheckCount : 4 , // config check, credentials check, 2 VM image checks (1 CP + 1 worker)
95- expectedFirstCheckName : "NutanixConfiguration" ,
96- expectedSecondCheckName : "NutanixCredentials" ,
97- vmImageCheckCount : 2 ,
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 ,
98104 },
99105 }
100106
@@ -107,6 +113,7 @@ func TestNutanixChecker_Init(t *testing.T) {
107113 configCheckCalled := false
108114 credsCheckCalled := false
109115 vmImageCheckCount := 0
116+ storageContainerCheckCount := 0
110117
111118 checker .configurationCheckFactory = func (cd * checkDependencies ) preflight.Check {
112119 configCheckCalled = true
@@ -144,6 +151,19 @@ func TestNutanixChecker_Init(t *testing.T) {
144151 return checks
145152 }
146153
154+ checker .initStorageContainerChecksFunc = func (n * nutanixChecker ) []preflight.Check {
155+ checks := []preflight.Check {}
156+ for i := 0 ; i < tt .storageContainerCheckCount ; i ++ {
157+ storageContainerCheckCount ++
158+ checks = append (checks , func (ctx context.Context ) preflight.CheckResult {
159+ return preflight.CheckResult {
160+ Name : fmt .Sprintf ("StorageContainerCheck-%d" , i ),
161+ }
162+ })
163+ }
164+ return checks
165+ }
166+
147167 // Call Init
148168 ctx := context .Background ()
149169 checks := checker .Init (ctx , nil , & clusterv1.Cluster {
@@ -160,6 +180,12 @@ func TestNutanixChecker_Init(t *testing.T) {
160180 assert .True (t , configCheckCalled , "initNutanixConfiguration should have been called" )
161181 assert .True (t , credsCheckCalled , "initCredentialsCheck should have been called" )
162182 assert .Equal (t , tt .vmImageCheckCount , vmImageCheckCount , "Wrong number of VM image checks" )
183+ assert .Equal (
184+ t ,
185+ tt .storageContainerCheckCount ,
186+ storageContainerCheckCount ,
187+ "Wrong number of storage container checks" ,
188+ )
163189
164190 // Verify the first two checks when we have results
165191 if len (checks ) >= 2 {
0 commit comments