@@ -133,66 +133,93 @@ func TestGetPodVMUUID(t *testing.T) {
133
133
})
134
134
}
135
135
136
- func TestVerifyStoragePolicyForVmfsWithEageredZeroThick (t * testing.T ) {
136
+ func TestVerifyStoragePolicyForVmfsUtil (t * testing.T ) {
137
137
ctx := context .TODO ()
138
-
139
- t .Run ("Valid VMFS EZT policy" , func (t * testing.T ) {
140
- policyList := []cnsvsphere.SpbmPolicyContent {
141
- {
142
- Profiles : []cnsvsphere.SpbmPolicySubProfile {
143
- {
144
- Rules : []cnsvsphere.SpbmPolicyRule {
145
- {Ns : vmfsNamespace , Value : vmfsNamespaceEztValue },
138
+ policyId := "policy-123"
139
+
140
+ tests := []struct {
141
+ name string
142
+ input []cnsvsphere.SpbmPolicyContent
143
+ expectError bool
144
+ }{
145
+ {
146
+ name : "Valid VMFS policy with EZT and Clustered VMDK" ,
147
+ input : []cnsvsphere.SpbmPolicyContent {
148
+ {
149
+ Profiles : []cnsvsphere.SpbmPolicySubProfile {
150
+ {
151
+ Rules : []cnsvsphere.SpbmPolicyRule {
152
+ {Ns : vmfsNamespace , Value : vmfsNamespaceEztValue },
153
+ {Ns : vmfsNamespace , Value : vmfsClusteredVmdk },
154
+ },
146
155
},
147
156
},
148
157
},
149
158
},
150
- }
151
-
152
- err := verifyStoragePolicyForVmfsWithEageredZeroThick (ctx , policyList , "valid-policy-id" )
153
- assert .NoError (t , err )
154
- })
155
-
156
- t .Run ("Invalid VMFS policy - not EZT" , func (t * testing.T ) {
157
- policyList := []cnsvsphere.SpbmPolicyContent {
158
- {
159
- Profiles : []cnsvsphere.SpbmPolicySubProfile {
160
- {
161
- Rules : []cnsvsphere.SpbmPolicyRule {
162
- {Ns : vmfsNamespace , Value : "Thin" },
159
+ expectError : false ,
160
+ },
161
+ {
162
+ name : "VMFS policy missing EZT" ,
163
+ input : []cnsvsphere.SpbmPolicyContent {
164
+ {
165
+ Profiles : []cnsvsphere.SpbmPolicySubProfile {
166
+ {
167
+ Rules : []cnsvsphere.SpbmPolicyRule {
168
+ {Ns : vmfsNamespace , Value : vmfsClusteredVmdk },
169
+ },
163
170
},
164
171
},
165
172
},
166
173
},
167
- }
168
-
169
- err := verifyStoragePolicyForVmfsWithEageredZeroThick (ctx , policyList , "invalid-policy-id" )
170
- assert .Error (t , err )
171
- assert .Contains (t , err .Error (), "must be fully initialized" )
172
- })
173
-
174
- t .Run ("Policy with no VMFS rule" , func (t * testing.T ) {
175
- policyList := []cnsvsphere.SpbmPolicyContent {
176
- {
177
- Profiles : []cnsvsphere.SpbmPolicySubProfile {
178
- {
179
- Rules : []cnsvsphere.SpbmPolicyRule {
180
- {Ns : "VSAN" , Value : "Whatever" },
174
+ expectError : true ,
175
+ },
176
+ {
177
+ name : "VMFS policy missing Clustered VMDK" ,
178
+ input : []cnsvsphere.SpbmPolicyContent {
179
+ {
180
+ Profiles : []cnsvsphere.SpbmPolicySubProfile {
181
+ {
182
+ Rules : []cnsvsphere.SpbmPolicyRule {
183
+ {Ns : vmfsNamespace , Value : vmfsNamespaceEztValue },
184
+ },
181
185
},
182
186
},
183
187
},
184
188
},
185
- }
186
-
187
- err := verifyStoragePolicyForVmfsWithEageredZeroThick (ctx , policyList , "no-vmfs-rule-policy" )
188
- assert .NoError (t , err )
189
- })
189
+ expectError : true ,
190
+ },
191
+ {
192
+ name : "Non-VMFS policy should pass" ,
193
+ input : []cnsvsphere.SpbmPolicyContent {
194
+ {
195
+ Profiles : []cnsvsphere.SpbmPolicySubProfile {
196
+ {
197
+ Rules : []cnsvsphere.SpbmPolicyRule {
198
+ {Ns : "non-vmfs" , Value : "some-value" },
199
+ },
200
+ },
201
+ },
202
+ },
203
+ },
204
+ expectError : false ,
205
+ },
206
+ {
207
+ name : "Empty policy list should pass" ,
208
+ input : []cnsvsphere.SpbmPolicyContent {},
209
+ expectError : false ,
210
+ },
211
+ }
190
212
191
- t .Run ("Empty policy list" , func (t * testing.T ) {
192
- var policyList []cnsvsphere.SpbmPolicyContent
193
- err := verifyStoragePolicyForVmfsWithEageredZeroThick (ctx , policyList , "empty-policy" )
194
- assert .NoError (t , err )
195
- })
213
+ for _ , tt := range tests {
214
+ t .Run (tt .name , func (t * testing.T ) {
215
+ err := verifyStoragePolicyForVmfsUtil (ctx , tt .input , policyId )
216
+ if tt .expectError {
217
+ assert .Error (t , err )
218
+ } else {
219
+ assert .NoError (t , err )
220
+ }
221
+ })
222
+ }
196
223
}
197
224
198
225
func newMockPod (name , namespace , nodeName string , volumes []string ,
0 commit comments