@@ -34,7 +34,7 @@ var _ = Describe("Leader election", func() {
34
34
client crclient.Client
35
35
)
36
36
BeforeEach (func () {
37
- client = fake .NewFakeClient (
37
+ client = fake .NewClientBuilder (). WithObjects (
38
38
& corev1.Pod {
39
39
ObjectMeta : metav1.ObjectMeta {
40
40
Name : "leader-test" ,
@@ -61,7 +61,7 @@ var _ = Describe("Leader election", func() {
61
61
},
62
62
},
63
63
},
64
- )
64
+ ). Build ()
65
65
})
66
66
It ("should return an error when POD_NAME is not set" , func () {
67
67
os .Unsetenv ("POD_NAME" )
@@ -118,14 +118,14 @@ var _ = Describe("Leader election", func() {
118
118
client crclient.Client
119
119
)
120
120
BeforeEach (func () {
121
- client = fake .NewFakeClient (
121
+ client = fake .NewClientBuilder (). WithObjects (
122
122
& corev1.Pod {
123
123
ObjectMeta : metav1.ObjectMeta {
124
124
Name : "mypod" ,
125
125
Namespace : "testns" ,
126
126
},
127
127
},
128
- )
128
+ ). Build ()
129
129
})
130
130
It ("should return an error when POD_NAME is not set" , func () {
131
131
os .Unsetenv ("POD_NAME" )
@@ -151,14 +151,14 @@ var _ = Describe("Leader election", func() {
151
151
client crclient.Client
152
152
)
153
153
BeforeEach (func () {
154
- client = fake .NewFakeClient (
154
+ client = fake .NewClientBuilder (). WithObjects (
155
155
& corev1.Pod {
156
156
ObjectMeta : metav1.ObjectMeta {
157
157
Name : "mypod" ,
158
158
Namespace : "testns" ,
159
159
},
160
160
},
161
- )
161
+ ). Build ()
162
162
})
163
163
It ("should return an error when POD_NAME is not set" , func () {
164
164
os .Unsetenv ("POD_NAME" )
@@ -185,13 +185,13 @@ var _ = Describe("Leader election", func() {
185
185
client crclient.Client
186
186
)
187
187
BeforeEach (func () {
188
- client = fake .NewFakeClient (
188
+ client = fake .NewClientBuilder (). WithObjects (
189
189
& corev1.Node {
190
190
ObjectMeta : metav1.ObjectMeta {
191
191
Name : "mynode" ,
192
192
},
193
193
},
194
- )
194
+ ). Build ()
195
195
})
196
196
It ("should return an error if no node is found" , func () {
197
197
node := corev1.Node {}
@@ -226,33 +226,33 @@ var _ = Describe("Leader election", func() {
226
226
})
227
227
228
228
It ("should return false if node is invalid" , func () {
229
- client = fake .NewFakeClient ()
229
+ client = fake .NewClientBuilder (). WithObjects (). Build ()
230
230
ret := isNotReadyNode (context .TODO (), client , "" )
231
231
Expect (ret ).To (Equal (false ))
232
232
})
233
233
It ("should return false if no NodeCondition is found" , func () {
234
- client = fake .NewFakeClient ( node )
234
+ client = fake .NewClientBuilder (). WithObjects ( node ). Build ( )
235
235
ret := isNotReadyNode (context .TODO (), client , nodeName )
236
236
Expect (ret ).To (Equal (false ))
237
237
})
238
238
It ("should return false if type is incorrect" , func () {
239
239
node .Status .Conditions [0 ].Type = corev1 .NodeMemoryPressure
240
240
node .Status .Conditions [0 ].Status = corev1 .ConditionFalse
241
- client = fake .NewFakeClient ( node )
241
+ client = fake .NewClientBuilder (). WithObjects ( node ). Build ( )
242
242
ret := isNotReadyNode (context .TODO (), client , nodeName )
243
243
Expect (ret ).To (Equal (false ))
244
244
})
245
245
It ("should return false if NodeReady's type is true" , func () {
246
246
node .Status .Conditions [0 ].Type = corev1 .NodeReady
247
247
node .Status .Conditions [0 ].Status = corev1 .ConditionTrue
248
- client = fake .NewFakeClient ( node )
248
+ client = fake .NewClientBuilder (). WithObjects ( node ). Build ( )
249
249
ret := isNotReadyNode (context .TODO (), client , nodeName )
250
250
Expect (ret ).To (Equal (false ))
251
251
})
252
252
It ("should return true when Type is set and Status is set to false" , func () {
253
253
node .Status .Conditions [0 ].Type = corev1 .NodeReady
254
254
node .Status .Conditions [0 ].Status = corev1 .ConditionFalse
255
- client = fake .NewFakeClient ( node )
255
+ client = fake .NewClientBuilder (). WithObjects ( node ). Build ( )
256
256
ret := isNotReadyNode (context .TODO (), client , nodeName )
257
257
Expect (ret ).To (Equal (true ))
258
258
})
@@ -292,27 +292,27 @@ var _ = Describe("Leader election", func() {
292
292
}
293
293
})
294
294
It ("should return an error if existing is not found" , func () {
295
- client = fake .NewFakeClient ( pod )
295
+ client = fake .NewClientBuilder (). WithObjects ( pod ). Build ( )
296
296
err := deleteLeader (context .TODO (), client , pod , configmap )
297
297
Expect (err ).ShouldNot (BeNil ())
298
298
})
299
299
It ("should return an error if pod is not found" , func () {
300
- client = fake .NewFakeClient ( configmap )
300
+ client = fake .NewClientBuilder (). WithObjects ( configmap ). Build ( )
301
301
err := deleteLeader (context .TODO (), client , pod , configmap )
302
302
Expect (err ).ShouldNot (BeNil ())
303
303
})
304
304
It ("should return an error if pod is nil" , func () {
305
- client = fake .NewFakeClient ( pod , configmap )
305
+ client = fake .NewClientBuilder (). WithObjects ( pod , configmap ). Build ( )
306
306
err := deleteLeader (context .TODO (), client , nil , configmap )
307
307
Expect (err ).ShouldNot (BeNil ())
308
308
})
309
309
It ("should return an error if configmap is nil" , func () {
310
- client = fake .NewFakeClient ( pod , configmap )
310
+ client = fake .NewClientBuilder (). WithObjects ( pod , configmap ). Build ( )
311
311
err := deleteLeader (context .TODO (), client , pod , nil )
312
312
Expect (err ).ShouldNot (BeNil ())
313
313
})
314
314
It ("should return nil if pod and configmap exists and configmap's owner is the pod" , func () {
315
- client = fake .NewFakeClient ( pod , configmap )
315
+ client = fake .NewClientBuilder (). WithObjects ( pod , configmap ). Build ( )
316
316
err := deleteLeader (context .TODO (), client , pod , configmap )
317
317
Expect (err ).Should (BeNil ())
318
318
})
0 commit comments