@@ -198,86 +198,86 @@ func Test_parseAutoDiscovery(t *testing.T) {
198198func Test_allowedByAutoDiscoverySpec (t * testing.T ) {
199199 for _ , tc := range []struct {
200200 name string
201- testSpec TestSpec
201+ testConfig * TestConfig
202202 autoDiscoveryConfig * clusterAPIAutoDiscoveryConfig
203203 additionalLabels map [string ]string
204204 shouldMatch bool
205205 }{{
206206 name : "no clustername, namespace, or label selector specified should match any MachineSet" ,
207- testSpec : createTestSpec ( RandomString ( 6 ), RandomString ( 6 ), RandomString ( 6 ), 1 , false , nil , nil ),
207+ testConfig : NewTestConfigBuilder (). ForMachineSet (). WithNodeCount ( 1 ). Build ( ),
208208 autoDiscoveryConfig : & clusterAPIAutoDiscoveryConfig {labelSelector : labels .NewSelector ()},
209209 shouldMatch : true ,
210210 }, {
211211 name : "no clustername, namespace, or label selector specified should match any MachineDeployment" ,
212- testSpec : createTestSpec ( RandomString ( 6 ), RandomString ( 6 ), RandomString ( 6 ), 1 , true , nil , nil ),
212+ testConfig : NewTestConfigBuilder (). ForMachineDeployment (). WithNodeCount ( 1 ). Build ( ),
213213 autoDiscoveryConfig : & clusterAPIAutoDiscoveryConfig {labelSelector : labels .NewSelector ()},
214214 shouldMatch : true ,
215215 }, {
216- name : "clustername specified does not match MachineSet, namespace matches, no labels specified" ,
217- testSpec : createTestSpec ( "default" , RandomString ( 6 ), RandomString ( 6 ), 1 , false , nil , nil ),
216+ name : "clustername specified does not match MachineSet, namespace matches, no labels specified" ,
217+ testConfig : NewTestConfigBuilder (). ForMachineSet (). WithNamespace ( "default" ). WithNodeCount ( 1 ). Build ( ),
218218 autoDiscoveryConfig : & clusterAPIAutoDiscoveryConfig {
219219 clusterName : "foo" ,
220220 namespace : "default" ,
221221 labelSelector : labels .NewSelector (),
222222 },
223223 shouldMatch : false ,
224224 }, {
225- name : "clustername specified does not match MachineDeployment, namespace matches, no labels specified" ,
226- testSpec : createTestSpec ( "default" , RandomString ( 6 ), RandomString ( 6 ), 1 , true , nil , nil ),
225+ name : "clustername specified does not match MachineDeployment, namespace matches, no labels specified" ,
226+ testConfig : NewTestConfigBuilder (). ForMachineDeployment (). WithNamespace ( "default" ). WithNodeCount ( 1 ). Build ( ),
227227 autoDiscoveryConfig : & clusterAPIAutoDiscoveryConfig {
228228 clusterName : "foo" ,
229229 namespace : "default" ,
230230 labelSelector : labels .NewSelector (),
231231 },
232232 shouldMatch : false ,
233233 }, {
234- name : "namespace specified does not match MachineSet, clusterName matches, no labels specified" ,
235- testSpec : createTestSpec ( RandomString ( 6 ), "foo" , RandomString ( 6 ), 1 , false , nil , nil ),
234+ name : "namespace specified does not match MachineSet, clusterName matches, no labels specified" ,
235+ testConfig : NewTestConfigBuilder (). ForMachineSet (). WithClusterName ( "foo" ). WithNodeCount ( 1 ). Build ( ),
236236 autoDiscoveryConfig : & clusterAPIAutoDiscoveryConfig {
237237 clusterName : "foo" ,
238238 namespace : "default" ,
239239 labelSelector : labels .NewSelector (),
240240 },
241241 shouldMatch : false ,
242242 }, {
243- name : "clustername specified does not match MachineDeployment, namespace matches, no labels specified" ,
244- testSpec : createTestSpec ( RandomString ( 6 ), "foo" , RandomString ( 6 ), 1 , true , nil , nil ),
243+ name : "clustername specified does not match MachineDeployment, namespace matches, no labels specified" ,
244+ testConfig : NewTestConfigBuilder (). ForMachineDeployment (). WithClusterName ( "foo" ). WithNodeCount ( 1 ). Build ( ),
245245 autoDiscoveryConfig : & clusterAPIAutoDiscoveryConfig {
246246 clusterName : "foo" ,
247247 namespace : "default" ,
248248 labelSelector : labels .NewSelector (),
249249 },
250250 shouldMatch : false ,
251251 }, {
252- name : "namespace and clusterName matches MachineSet, no labels specified" ,
253- testSpec : createTestSpec ( "default" , "foo" , RandomString ( 6 ), 1 , false , nil , nil ),
252+ name : "namespace and clusterName matches MachineSet, no labels specified" ,
253+ testConfig : NewTestConfigBuilder (). ForMachineSet (). WithNamespace ( "default" ). WithClusterName ( "foo" ). WithNodeCount ( 1 ). Build ( ),
254254 autoDiscoveryConfig : & clusterAPIAutoDiscoveryConfig {
255255 clusterName : "foo" ,
256256 namespace : "default" ,
257257 labelSelector : labels .NewSelector (),
258258 },
259259 shouldMatch : true ,
260260 }, {
261- name : "namespace and clusterName matches MachineDeployment, no labels specified" ,
262- testSpec : createTestSpec ( "default" , "foo" , RandomString ( 6 ), 1 , true , nil , nil ),
261+ name : "namespace and clusterName matches MachineDeployment, no labels specified" ,
262+ testConfig : NewTestConfigBuilder (). ForMachineDeployment (). WithNamespace ( "default" ). WithClusterName ( "foo" ). WithNodeCount ( 1 ). Build ( ),
263263 autoDiscoveryConfig : & clusterAPIAutoDiscoveryConfig {
264264 clusterName : "foo" ,
265265 namespace : "default" ,
266266 labelSelector : labels .NewSelector (),
267267 },
268268 shouldMatch : true ,
269269 }, {
270- name : "namespace and clusterName matches MachineSet, does not match label selector" ,
271- testSpec : createTestSpec ( "default" , "foo" , RandomString ( 6 ), 1 , false , nil , nil ),
270+ name : "namespace and clusterName matches MachineSet, does not match label selector" ,
271+ testConfig : NewTestConfigBuilder (). ForMachineSet (). WithNamespace ( "default" ). WithClusterName ( "foo" ). WithNodeCount ( 1 ). Build ( ),
272272 autoDiscoveryConfig : & clusterAPIAutoDiscoveryConfig {
273273 clusterName : "foo" ,
274274 namespace : "default" ,
275275 labelSelector : labels .SelectorFromSet (labels.Set {"color" : "green" }),
276276 },
277277 shouldMatch : false ,
278278 }, {
279- name : "namespace and clusterName matches MachineDeployment, does not match label selector" ,
280- testSpec : createTestSpec ( "default" , "foo" , RandomString ( 6 ), 1 , true , nil , nil ),
279+ name : "namespace and clusterName matches MachineDeployment, does not match label selector" ,
280+ testConfig : NewTestConfigBuilder (). ForMachineDeployment (). WithNamespace ( "default" ). WithClusterName ( "foo" ). WithNodeCount ( 1 ). Build ( ),
281281 autoDiscoveryConfig : & clusterAPIAutoDiscoveryConfig {
282282 clusterName : "foo" ,
283283 namespace : "default" ,
@@ -286,7 +286,7 @@ func Test_allowedByAutoDiscoverySpec(t *testing.T) {
286286 shouldMatch : false ,
287287 }, {
288288 name : "namespace, clusterName, and label selector matches MachineSet" ,
289- testSpec : createTestSpec ( "default" , "foo" , RandomString ( 6 ), 1 , false , nil , nil ),
289+ testConfig : NewTestConfigBuilder (). ForMachineSet (). WithNamespace ( "default" ). WithClusterName ( "foo" ). WithNodeCount ( 1 ). Build ( ),
290290 additionalLabels : map [string ]string {"color" : "green" },
291291 autoDiscoveryConfig : & clusterAPIAutoDiscoveryConfig {
292292 clusterName : "foo" ,
@@ -296,7 +296,7 @@ func Test_allowedByAutoDiscoverySpec(t *testing.T) {
296296 shouldMatch : true ,
297297 }, {
298298 name : "namespace, clusterName, and label selector matches MachineDeployment" ,
299- testSpec : createTestSpec ( "default" , "foo" , RandomString ( 6 ), 1 , true , nil , nil ),
299+ testConfig : NewTestConfigBuilder (). ForMachineDeployment (). WithNamespace ( "default" ). WithClusterName ( "foo" ). WithNodeCount ( 1 ). Build ( ),
300300 additionalLabels : map [string ]string {"color" : "green" },
301301 autoDiscoveryConfig : & clusterAPIAutoDiscoveryConfig {
302302 clusterName : "foo" ,
@@ -306,10 +306,9 @@ func Test_allowedByAutoDiscoverySpec(t *testing.T) {
306306 shouldMatch : true ,
307307 }} {
308308 t .Run (tc .name , func (t * testing.T ) {
309- testConfigs := createTestConfigs (tc .testSpec )
310- resource := testConfigs [0 ].machineSet
311- if tc .testSpec .rootIsMachineDeployment {
312- resource = testConfigs [0 ].machineDeployment
309+ resource := tc .testConfig .machineSet
310+ if tc .testConfig .machineDeployment != nil {
311+ resource = tc .testConfig .machineDeployment
313312 }
314313 if tc .additionalLabels != nil {
315314 resource .SetLabels (labels .Merge (resource .GetLabels (), tc .additionalLabels ))
0 commit comments