@@ -33,22 +33,24 @@ func (m *mockCheck) Run(ctx context.Context) preflight.CheckResult {
33
33
34
34
func TestNutanixChecker_Init (t * testing.T ) {
35
35
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
43
44
}{
44
45
{
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 ,
52
54
},
53
55
{
54
56
name : "initialization with control plane config" ,
@@ -57,11 +59,12 @@ func TestNutanixChecker_Init(t *testing.T) {
57
59
Nutanix : & carenv1.NutanixNodeSpec {},
58
60
},
59
61
},
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 ,
65
68
},
66
69
{
67
70
name : "initialization with worker node configs" ,
@@ -74,10 +77,11 @@ func TestNutanixChecker_Init(t *testing.T) {
74
77
Nutanix : & carenv1.NutanixNodeSpec {},
75
78
},
76
79
},
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 ,
81
85
},
82
86
{
83
87
name : "initialization with both control plane and worker node configs" ,
@@ -91,10 +95,12 @@ func TestNutanixChecker_Init(t *testing.T) {
91
95
Nutanix : & carenv1.NutanixNodeSpec {},
92
96
},
93
97
},
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 ,
98
104
},
99
105
}
100
106
@@ -107,6 +113,7 @@ func TestNutanixChecker_Init(t *testing.T) {
107
113
configCheckCalled := false
108
114
credsCheckCalled := false
109
115
vmImageCheckCount := 0
116
+ storageContainerCheckCount := 0
110
117
111
118
checker .configurationCheckFactory = func (cd * checkDependencies ) preflight.Check {
112
119
configCheckCalled = true
@@ -144,6 +151,22 @@ func TestNutanixChecker_Init(t *testing.T) {
144
151
return checks
145
152
}
146
153
154
+ checker .storageContainerChecksFactory = func (cd * checkDependencies ) []preflight.Check {
155
+ checks := []preflight.Check {}
156
+ for i := 0 ; i < tt .storageContainerCheckCount ; i ++ {
157
+ storageContainerCheckCount ++
158
+ checks = append (checks ,
159
+ & mockCheck {
160
+ name : fmt .Sprintf ("NutanixStorageContainer-%d" , i ),
161
+ result : preflight.CheckResult {
162
+ Allowed : true ,
163
+ },
164
+ },
165
+ )
166
+ }
167
+ return checks
168
+ }
169
+
147
170
// Call Init
148
171
ctx := context .Background ()
149
172
checks := checker .Init (ctx , nil , & clusterv1.Cluster {
@@ -160,6 +183,12 @@ func TestNutanixChecker_Init(t *testing.T) {
160
183
assert .True (t , configCheckCalled , "initNutanixConfiguration should have been called" )
161
184
assert .True (t , credsCheckCalled , "initCredentialsCheck should have been called" )
162
185
assert .Equal (t , tt .vmImageCheckCount , vmImageCheckCount , "Wrong number of VM image checks" )
186
+ assert .Equal (
187
+ t ,
188
+ tt .storageContainerCheckCount ,
189
+ storageContainerCheckCount ,
190
+ "Wrong number of storage container checks" ,
191
+ )
163
192
164
193
// Verify the first two checks when we have results
165
194
if len (checks ) >= 2 {
0 commit comments