@@ -42,7 +42,7 @@ func TestRayClusterGetComplete(t *testing.T) {
42
42
name : "neither namespace nor args set" ,
43
43
namespace : "" ,
44
44
args : []string {},
45
- expectedAllNamespaces : true ,
45
+ expectedAllNamespaces : false ,
46
46
expectedCluster : "" ,
47
47
},
48
48
{
@@ -56,7 +56,7 @@ func TestRayClusterGetComplete(t *testing.T) {
56
56
name : "namespace not set, args set" ,
57
57
namespace : "" ,
58
58
args : []string {"foo" , "bar" },
59
- expectedAllNamespaces : true ,
59
+ expectedAllNamespaces : false ,
60
60
expectedCluster : "foo" ,
61
61
},
62
62
{
@@ -223,75 +223,102 @@ func TestGetRayClusters(t *testing.T) {
223
223
},
224
224
}
225
225
226
+ defaultNamespace := "default"
227
+ rayClusterInDefault := & rayv1.RayCluster {
228
+ ObjectMeta : v1.ObjectMeta {
229
+ Name : "raycluster-kuberay-default" ,
230
+ Namespace : defaultNamespace ,
231
+ },
232
+ }
233
+
226
234
tests := []struct {
227
- namespace * string
228
- name string
229
- expectedError string
230
- expectedOutput string
231
- cluster string
232
- rayClusters []runtime.Object
235
+ namespace * string
236
+ name string
237
+ expectedError string
238
+ expectedOutput string
239
+ cluster string
240
+ expectedRayClusters []runtime.Object
241
+ allFakeRayClusters []runtime.Object
242
+ allNamespaces bool
233
243
}{
234
244
{
235
- name : "should not error if no cluster name is provided, searching all namespaces, and no clusters are found" ,
236
- namespace : nil ,
237
- rayClusters : []runtime.Object {},
245
+ name : "should not error if no cluster name is provided, searching all namespaces, and no clusters are found" ,
246
+ namespace : nil ,
247
+ expectedRayClusters : []runtime.Object {},
248
+ },
249
+ {
250
+ name : "should error if a cluster name is provided, searching all namespaces, and no clusters are found" ,
251
+ cluster : "my-cluster" ,
252
+ namespace : nil ,
253
+ expectedRayClusters : []runtime.Object {},
254
+ expectedError : "Ray cluster my-cluster not found" ,
255
+ },
256
+ {
257
+ name : "should not error if no cluster name is provided, searching one namespace, and no clusters are found" ,
258
+ namespace : & namespace ,
259
+ expectedRayClusters : []runtime.Object {},
238
260
},
239
261
{
240
- name : "should error if a cluster name is provided, searching all namespaces , and no clusters are found" ,
241
- cluster : "my-cluster" ,
242
- namespace : nil ,
243
- rayClusters : []runtime.Object {},
244
- expectedError : "Ray cluster my-cluster not found" ,
262
+ name : "should error if a cluster name is provided, searching one namespace , and no clusters are found" ,
263
+ cluster : "my-cluster" ,
264
+ namespace : & namespace ,
265
+ expectedRayClusters : []runtime.Object {},
266
+ expectedError : fmt . Sprintf ( "Ray cluster my-cluster not found in namespace %s" , namespace ) ,
245
267
},
246
268
{
247
- name : "should not error if no cluster name is provided, searching one namespace, and no clusters are found" ,
248
- namespace : & namespace ,
249
- rayClusters : []runtime.Object {},
269
+ name : "should not error if no cluster name is provided, searching all namespaces, and clusters are found" ,
270
+ namespace : nil ,
271
+ allFakeRayClusters : []runtime.Object {rayCluster },
272
+ expectedRayClusters : []runtime.Object {rayCluster },
250
273
},
251
274
{
252
- name : "should error if a cluster name is provided, searching one namespace , and no clusters are found" ,
253
- cluster : "my-cluster" ,
254
- namespace : & namespace ,
255
- rayClusters : []runtime.Object {},
256
- expectedError : fmt . Sprintf ( "Ray cluster my-cluster not found in namespace %s" , namespace ) ,
275
+ name : "should not error if a cluster name is provided, searching all namespaces , and clusters are found" ,
276
+ cluster : "my-cluster" ,
277
+ namespace : nil ,
278
+ allFakeRayClusters : []runtime.Object {rayCluster },
279
+ expectedRayClusters : []runtime. Object { rayCluster } ,
257
280
},
258
281
{
259
- name : "should not error if no cluster name is provided, searching all namespaces, and clusters are found" ,
260
- namespace : nil ,
261
- rayClusters : []runtime.Object {rayCluster },
282
+ name : "should not error if no cluster name is provided, searching one namespace, and clusters are found" ,
283
+ namespace : & namespace ,
284
+ allFakeRayClusters : []runtime.Object {rayCluster },
285
+ expectedRayClusters : []runtime.Object {rayCluster },
262
286
},
263
287
{
264
- name : "should not error if a cluster name is provided, searching all namespaces, and clusters are found" ,
265
- cluster : "my-cluster" ,
266
- namespace : nil ,
267
- rayClusters : []runtime.Object {rayCluster },
288
+ name : "should not error if a cluster name is provided, searching one namespace, and clusters are found" ,
289
+ cluster : "my-cluster" ,
290
+ namespace : & namespace ,
291
+ allFakeRayClusters : []runtime.Object {rayCluster },
292
+ expectedRayClusters : []runtime.Object {rayCluster },
268
293
},
269
294
{
270
- name : "should not error if no cluster name is provided, searching one namespace, and clusters are found" ,
271
- namespace : & namespace ,
272
- rayClusters : []runtime.Object {rayCluster },
295
+ name : "should not error if no cluster name is provided, searching default namespace, and clusters are found" ,
296
+ namespace : & defaultNamespace ,
297
+ allFakeRayClusters : []runtime.Object {rayCluster , rayClusterInDefault },
298
+ expectedRayClusters : []runtime.Object {rayClusterInDefault },
273
299
},
274
300
{
275
- name : "should not error if a cluster name is provided, searching one namespace, and clusters are found" ,
276
- cluster : "my-cluster" ,
277
- namespace : & namespace ,
278
- rayClusters : []runtime.Object {rayCluster },
301
+ name : "should not error if no cluster name is provided, searching all namespace, and clusters are found" ,
302
+ allNamespaces : true ,
303
+ allFakeRayClusters : []runtime. Object { rayCluster , rayClusterInDefault } ,
304
+ expectedRayClusters : []runtime.Object {rayCluster , rayClusterInDefault },
279
305
},
280
306
}
281
307
282
308
for _ , tc := range tests {
283
309
t .Run (tc .name , func (t * testing.T ) {
284
310
fakeClusterGetOptions := GetClusterOptions {
285
- cmdFactory : cmdFactory ,
286
- ioStreams : & testStreams ,
287
- cluster : tc .cluster ,
311
+ cmdFactory : cmdFactory ,
312
+ ioStreams : & testStreams ,
313
+ cluster : tc .cluster ,
314
+ allNamespaces : tc .allNamespaces ,
288
315
}
289
316
if tc .namespace != nil {
290
317
fakeClusterGetOptions .namespace = * tc .namespace
291
318
}
292
319
293
320
kubeClientSet := kubefake .NewClientset ()
294
- rayClient := rayClientFake .NewSimpleClientset (tc .rayClusters ... )
321
+ rayClient := rayClientFake .NewSimpleClientset (tc .allFakeRayClusters ... )
295
322
k8sClients := client .NewClientForTesting (kubeClientSet , rayClient )
296
323
297
324
rayClusters , err := getRayClusters (context .Background (), & fakeClusterGetOptions , k8sClients )
@@ -302,7 +329,7 @@ func TestGetRayClusters(t *testing.T) {
302
329
}
303
330
304
331
require .NoError (t , err )
305
- assert .Equal (t , len (tc .rayClusters ), len (rayClusters .Items ))
332
+ assert .Equal (t , len (tc .expectedRayClusters ), len (rayClusters .Items ))
306
333
})
307
334
}
308
335
}
0 commit comments