@@ -236,135 +236,6 @@ func Test_ValidateClusterVariables(t *testing.T) {
236236 }
237237}
238238
239- func Test_ValidateTopLevelClusterVariablesExist (t * testing.T ) {
240- tests := []struct {
241- name string
242- clusterVariablesOverrides []clusterv1.ClusterVariable
243- clusterVariables []clusterv1.ClusterVariable
244- wantErr bool
245- }{
246- {
247- name : "Pass if all variable overrides have corresponding top-level variables." ,
248- clusterVariablesOverrides : []clusterv1.ClusterVariable {
249- {
250- Name : "cpu" ,
251- Value : apiextensionsv1.JSON {
252- Raw : []byte (`1` ),
253- },
254- },
255- {
256- Name : "zone" ,
257- Value : apiextensionsv1.JSON {
258- Raw : []byte (`"longerThanOneCharacter"` ),
259- },
260- },
261- },
262- clusterVariables : []clusterv1.ClusterVariable {
263- {
264- Name : "cpu" ,
265- Value : apiextensionsv1.JSON {
266- Raw : []byte (`1` ),
267- },
268- },
269- {
270- Name : "zone" ,
271- Value : apiextensionsv1.JSON {
272- Raw : []byte (`"longerThanOneCharacter"` ),
273- },
274- },
275- },
276- },
277- {
278- name : "Pass if there are no variable overrides and no top-level variables." ,
279- clusterVariablesOverrides : []clusterv1.ClusterVariable {},
280- clusterVariables : []clusterv1.ClusterVariable {},
281- },
282- {
283- name : "Pass if there are no variable overrides." ,
284- clusterVariablesOverrides : []clusterv1.ClusterVariable {},
285- clusterVariables : []clusterv1.ClusterVariable {
286- {
287- Name : "cpu" ,
288- Value : apiextensionsv1.JSON {
289- Raw : []byte (`1` ),
290- },
291- },
292- {
293- Name : "zone" ,
294- Value : apiextensionsv1.JSON {
295- Raw : []byte (`"longerThanOneCharacter"` ),
296- },
297- },
298- },
299- },
300- {
301- name : "Error if a variable override is missing the corresponding top-level variables." ,
302- clusterVariablesOverrides : []clusterv1.ClusterVariable {
303- {
304- Name : "cpu" ,
305- Value : apiextensionsv1.JSON {
306- Raw : []byte (`1` ),
307- },
308- },
309- {
310- Name : "zone" ,
311- Value : apiextensionsv1.JSON {
312- Raw : []byte (`"longerThanOneCharacter"` ),
313- },
314- },
315- },
316- clusterVariables : []clusterv1.ClusterVariable {
317- {
318- Name : "zone" ,
319- Value : apiextensionsv1.JSON {
320- Raw : []byte (`"longerThanOneCharacter"` ),
321- },
322- },
323- },
324- wantErr : true ,
325- },
326- {
327- name : "Pass if not every top-level variable has an override." ,
328- clusterVariablesOverrides : []clusterv1.ClusterVariable {
329- {
330- Name : "zone" ,
331- Value : apiextensionsv1.JSON {
332- Raw : []byte (`"longerThanOneCharacter"` ),
333- },
334- },
335- },
336- clusterVariables : []clusterv1.ClusterVariable {
337- {
338- Name : "cpu" ,
339- Value : apiextensionsv1.JSON {
340- Raw : []byte (`1` ),
341- },
342- },
343- {
344- Name : "zone" ,
345- Value : apiextensionsv1.JSON {
346- Raw : []byte (`"longerThanOneCharacter"` ),
347- },
348- },
349- },
350- },
351- }
352- for _ , tt := range tests {
353- t .Run (tt .name , func (t * testing.T ) {
354- g := NewWithT (t )
355-
356- errList := ValidateTopLevelClusterVariablesExist (tt .clusterVariablesOverrides , tt .clusterVariables ,
357- field .NewPath ("spec" , "topology" , "workers" , "machineDeployments" ).Index (0 ).Child ("variables" , "overrides" ))
358-
359- if tt .wantErr {
360- g .Expect (errList ).NotTo (BeEmpty ())
361- return
362- }
363- g .Expect (errList ).To (BeEmpty ())
364- })
365- }
366- }
367-
368239func Test_ValidateClusterVariable (t * testing.T ) {
369240 tests := []struct {
370241 name string
0 commit comments