@@ -28,13 +28,12 @@ var (
28
28
29
29
func TestNew (t * testing.T ) {
30
30
type args struct {
31
- clusterID string
32
- region string
33
- apiKey string
34
- apiURL string
35
- nodePoolID string
36
- nodeDesiredGPUCount string
37
- opts []Option
31
+ clusterID string
32
+ region string
33
+ apiKey string
34
+ apiURL string
35
+ nodePoolID string
36
+ opts []Option
38
37
}
39
38
type test struct {
40
39
name string
@@ -47,17 +46,15 @@ func TestNew(t *testing.T) {
47
46
{
48
47
name : "Returns no error when given valid input" ,
49
48
args : args {
50
- clusterID : testClusterID ,
51
- region : testRegion ,
52
- apiKey : testApiKey ,
53
- apiURL : testApiURL ,
54
- nodePoolID : testNodePoolID ,
55
- nodeDesiredGPUCount : testNodeDesiredGPUCount ,
49
+ clusterID : testClusterID ,
50
+ region : testRegion ,
51
+ apiKey : testApiKey ,
52
+ apiURL : testApiURL ,
53
+ nodePoolID : testNodePoolID ,
56
54
opts : []Option {
57
55
WithKubernetesClient (fake .NewSimpleClientset ()),
58
56
WithCivoClient (& FakeClient {}),
59
- WithRebootTimeWindowMinutes ("invalid time" ), // It is invalid, but the default time (40) will be used.
60
- WithRebootTimeWindowMinutes ("0" ), // It is invalid, but the default time (40) will be used.
57
+ WithDesiredGPUCount (testNodeDesiredGPUCount ),
61
58
},
62
59
},
63
60
checkFunc : func (w * watcher ) error {
@@ -97,51 +94,66 @@ func TestNew(t *testing.T) {
97
94
},
98
95
},
99
96
{
100
- name : "Returns an error when clusterID is missing " ,
97
+ name : "Returns no error when input is invalid, but default value is set " ,
101
98
args : args {
102
- region : testRegion ,
103
- apiKey : testApiKey ,
104
- apiURL : testApiURL ,
105
- nodePoolID : testNodePoolID ,
106
- nodeDesiredGPUCount : testNodeDesiredGPUCount ,
99
+ clusterID : testClusterID ,
100
+ region : testRegion ,
101
+ apiKey : testApiKey ,
102
+ apiURL : testApiURL ,
103
+ nodePoolID : testNodePoolID ,
107
104
opts : []Option {
108
105
WithKubernetesClient (fake .NewSimpleClientset ()),
109
106
WithCivoClient (& FakeClient {}),
107
+ WithDesiredGPUCount ("invalid" ), // It is invalid, but the default count (0) will be used.
108
+ WithDesiredGPUCount ("-1" ), // It is invalid, but the default count (0) will be used.
109
+ WithRebootTimeWindowMinutes ("invalid time" ), // It is invalid, but the default time (40) will be used.
110
+ WithRebootTimeWindowMinutes ("0" ), // It is invalid, but the default time (40) will be used.
110
111
},
111
112
},
112
- wantErr : true ,
113
+ checkFunc : func (w * watcher ) error {
114
+ if w .nodeDesiredGPUCount != 0 {
115
+ return fmt .Errorf ("w.nodeDesiredGPUCount mismatch: got %d, want %d" , w .nodeDesiredGPUCount , 0 )
116
+ }
117
+ if w .rebootTimeWindowMinutes != testRebootTimeWindowMinutes {
118
+ return fmt .Errorf ("w.rebootTimeWindowMinutes mismatch: got %v, want %s" , w .nodeSelector , testNodePoolID )
119
+ }
120
+ return nil
121
+ },
113
122
},
114
123
{
115
- name : "Returns an error when nodeDesiredGPUCount is invalid " ,
124
+ name : "Returns no error when nodeDesiredGPUCount is 0 " ,
116
125
args : args {
117
- clusterID : testClusterID ,
118
- region : testRegion ,
119
- apiKey : testApiKey ,
120
- apiURL : testApiURL ,
121
- nodePoolID : testNodePoolID ,
122
- nodeDesiredGPUCount : "invalid_number" ,
126
+ clusterID : testClusterID ,
127
+ region : testRegion ,
128
+ apiKey : testApiKey ,
129
+ apiURL : testApiURL ,
130
+ nodePoolID : testNodePoolID ,
123
131
opts : []Option {
124
132
WithKubernetesClient (fake .NewSimpleClientset ()),
125
133
WithCivoClient (& FakeClient {}),
134
+ WithDesiredGPUCount ("0" ),
126
135
},
127
136
},
128
- wantErr : true ,
137
+ checkFunc : func (w * watcher ) error {
138
+ if w .nodeDesiredGPUCount != 0 {
139
+ return fmt .Errorf ("w.nodeDesiredGPUCount mismatch: got %d, want %d" , w .nodeDesiredGPUCount , 0 )
140
+ }
141
+ return nil
142
+ },
129
143
},
130
144
{
131
- name : "Returns an error when nodeDesiredGPUCount is 0 " ,
145
+ name : "Returns an error when clusterID is missing " ,
132
146
args : args {
133
- clusterID : testClusterID ,
134
- region : testRegion ,
135
- apiKey : testApiKey ,
136
- apiURL : testApiURL ,
137
- nodePoolID : testNodePoolID ,
138
- nodeDesiredGPUCount : "0" ,
147
+ region : testRegion ,
148
+ apiKey : testApiKey ,
149
+ apiURL : testApiURL ,
150
+ nodePoolID : testNodePoolID ,
139
151
opts : []Option {
140
152
WithKubernetesClient (fake .NewSimpleClientset ()),
141
153
WithCivoClient (& FakeClient {}),
142
154
},
143
155
},
144
- wantErr : false ,
156
+ wantErr : true ,
145
157
},
146
158
}
147
159
@@ -153,7 +165,6 @@ func TestNew(t *testing.T) {
153
165
test .args .region ,
154
166
test .args .clusterID ,
155
167
test .args .nodePoolID ,
156
- test .args .nodeDesiredGPUCount ,
157
168
test .args .opts ... )
158
169
if (err != nil ) != test .wantErr {
159
170
t .Errorf ("error = %v, wantErr %v" , err , test .wantErr )
@@ -177,9 +188,8 @@ func TestNew(t *testing.T) {
177
188
178
189
func TestRun (t * testing.T ) {
179
190
type args struct {
180
- opts []Option
181
- nodeDesiredGPUCount string
182
- nodePoolID string
191
+ opts []Option
192
+ nodePoolID string
183
193
}
184
194
type test struct {
185
195
name string
@@ -195,9 +205,9 @@ func TestRun(t *testing.T) {
195
205
opts : []Option {
196
206
WithKubernetesClient (fake .NewSimpleClientset ()),
197
207
WithCivoClient (& FakeClient {}),
208
+ WithDesiredGPUCount (testNodeDesiredGPUCount ),
198
209
},
199
- nodeDesiredGPUCount : testNodeDesiredGPUCount ,
200
- nodePoolID : testNodePoolID ,
210
+ nodePoolID : testNodePoolID ,
201
211
},
202
212
beforeFunc : func (w * watcher ) {
203
213
t .Helper ()
@@ -241,9 +251,9 @@ func TestRun(t *testing.T) {
241
251
opts : []Option {
242
252
WithKubernetesClient (fake .NewSimpleClientset ()),
243
253
WithCivoClient (& FakeClient {}),
254
+ WithDesiredGPUCount (testNodeDesiredGPUCount ),
244
255
},
245
- nodeDesiredGPUCount : testNodeDesiredGPUCount ,
246
- nodePoolID : testNodePoolID ,
256
+ nodePoolID : testNodePoolID ,
247
257
},
248
258
beforeFunc : func (w * watcher ) {
249
259
t .Helper ()
@@ -298,9 +308,9 @@ func TestRun(t *testing.T) {
298
308
opts : []Option {
299
309
WithKubernetesClient (fake .NewSimpleClientset ()),
300
310
WithCivoClient (& FakeClient {}),
311
+ WithDesiredGPUCount (testNodeDesiredGPUCount ),
301
312
},
302
- nodeDesiredGPUCount : testNodeDesiredGPUCount ,
303
- nodePoolID : testNodePoolID ,
313
+ nodePoolID : testNodePoolID ,
304
314
},
305
315
beforeFunc : func (w * watcher ) {
306
316
t .Helper ()
@@ -351,9 +361,9 @@ func TestRun(t *testing.T) {
351
361
opts : []Option {
352
362
WithKubernetesClient (fake .NewSimpleClientset ()),
353
363
WithCivoClient (& FakeClient {}),
364
+ WithDesiredGPUCount (testNodeDesiredGPUCount ),
354
365
},
355
- nodeDesiredGPUCount : testNodeDesiredGPUCount ,
356
- nodePoolID : testNodePoolID ,
366
+ nodePoolID : testNodePoolID ,
357
367
},
358
368
beforeFunc : func (w * watcher ) {
359
369
t .Helper ()
@@ -394,9 +404,9 @@ func TestRun(t *testing.T) {
394
404
opts : []Option {
395
405
WithKubernetesClient (fake .NewSimpleClientset ()),
396
406
WithCivoClient (& FakeClient {}),
407
+ WithDesiredGPUCount (testNodeDesiredGPUCount ),
397
408
},
398
- nodeDesiredGPUCount : testNodeDesiredGPUCount ,
399
- nodePoolID : testNodePoolID ,
409
+ nodePoolID : testNodePoolID ,
400
410
},
401
411
beforeFunc : func (w * watcher ) {
402
412
t .Helper ()
@@ -415,9 +425,9 @@ func TestRun(t *testing.T) {
415
425
opts : []Option {
416
426
WithKubernetesClient (fake .NewSimpleClientset ()),
417
427
WithCivoClient (& FakeClient {}),
428
+ WithDesiredGPUCount (testNodeDesiredGPUCount ),
418
429
},
419
- nodeDesiredGPUCount : testNodeDesiredGPUCount ,
420
- nodePoolID : testNodePoolID ,
430
+ nodePoolID : testNodePoolID ,
421
431
},
422
432
beforeFunc : func (w * watcher ) {
423
433
t .Helper ()
@@ -462,7 +472,7 @@ func TestRun(t *testing.T) {
462
472
for _ , test := range tests {
463
473
t .Run (test .name , func (t * testing.T ) {
464
474
w , err := NewWatcher (t .Context (),
465
- testApiURL , testApiKey , testRegion , testClusterID , test .args .nodePoolID , test .args .nodeDesiredGPUCount , test . args . opts ... )
475
+ testApiURL , testApiKey , testRegion , testClusterID , test .args .nodePoolID , test .args .opts ... )
466
476
if err != nil {
467
477
t .Fatal (err )
468
478
}
@@ -682,6 +692,19 @@ func TestIsNodeDesiredGPU(t *testing.T) {
682
692
desired : 8 ,
683
693
want : true ,
684
694
},
695
+ {
696
+ name : "Returns true when desired GPU count is, so count check is skipped" ,
697
+ node : & corev1.Node {
698
+ ObjectMeta : metav1.ObjectMeta {
699
+ Name : "node-01" ,
700
+ },
701
+ Status : corev1.NodeStatus {
702
+ Allocatable : corev1.ResourceList {},
703
+ },
704
+ },
705
+ desired : 0 ,
706
+ want : true ,
707
+ },
685
708
{
686
709
name : "Returns false when GPU count is 0" ,
687
710
node : & corev1.Node {
@@ -744,6 +767,7 @@ func TestRebootNode(t *testing.T) {
744
767
opts : []Option {
745
768
WithKubernetesClient (fake .NewSimpleClientset ()),
746
769
WithCivoClient (& FakeClient {}),
770
+ WithDesiredGPUCount (testNodeDesiredGPUCount ),
747
771
},
748
772
},
749
773
beforeFunc : func (t * testing.T , w * watcher ) {
@@ -772,6 +796,7 @@ func TestRebootNode(t *testing.T) {
772
796
opts : []Option {
773
797
WithKubernetesClient (fake .NewSimpleClientset ()),
774
798
WithCivoClient (& FakeClient {}),
799
+ WithDesiredGPUCount (testNodeDesiredGPUCount ),
775
800
},
776
801
},
777
802
beforeFunc : func (t * testing.T , w * watcher ) {
@@ -791,6 +816,7 @@ func TestRebootNode(t *testing.T) {
791
816
opts : []Option {
792
817
WithKubernetesClient (fake .NewSimpleClientset ()),
793
818
WithCivoClient (& FakeClient {}),
819
+ WithDesiredGPUCount (testNodeDesiredGPUCount ),
794
820
},
795
821
},
796
822
beforeFunc : func (t * testing.T , w * watcher ) {
@@ -818,7 +844,7 @@ func TestRebootNode(t *testing.T) {
818
844
for _ , test := range tests {
819
845
t .Run (test .name , func (t * testing.T ) {
820
846
w , err := NewWatcher (t .Context (),
821
- testApiURL , testApiKey , testRegion , testClusterID , testNodePoolID , testNodeDesiredGPUCount , test .args .opts ... )
847
+ testApiURL , testApiKey , testRegion , testClusterID , testNodePoolID , test .args .opts ... )
822
848
if err != nil {
823
849
t .Fatal (err )
824
850
}
0 commit comments