@@ -34,7 +34,7 @@ var _ = Describe("Leader election", func() {
3434 client crclient.Client
3535 )
3636 BeforeEach (func () {
37- client = fake .NewFakeClient (
37+ client = fake .NewClientBuilder (). WithObjects (
3838 & corev1.Pod {
3939 ObjectMeta : metav1.ObjectMeta {
4040 Name : "leader-test" ,
@@ -61,7 +61,7 @@ var _ = Describe("Leader election", func() {
6161 },
6262 },
6363 },
64- )
64+ ). Build ()
6565 })
6666 It ("should return an error when POD_NAME is not set" , func () {
6767 os .Unsetenv ("POD_NAME" )
@@ -118,14 +118,14 @@ var _ = Describe("Leader election", func() {
118118 client crclient.Client
119119 )
120120 BeforeEach (func () {
121- client = fake .NewFakeClient (
121+ client = fake .NewClientBuilder (). WithObjects (
122122 & corev1.Pod {
123123 ObjectMeta : metav1.ObjectMeta {
124124 Name : "mypod" ,
125125 Namespace : "testns" ,
126126 },
127127 },
128- )
128+ ). Build ()
129129 })
130130 It ("should return an error when POD_NAME is not set" , func () {
131131 os .Unsetenv ("POD_NAME" )
@@ -151,14 +151,14 @@ var _ = Describe("Leader election", func() {
151151 client crclient.Client
152152 )
153153 BeforeEach (func () {
154- client = fake .NewFakeClient (
154+ client = fake .NewClientBuilder (). WithObjects (
155155 & corev1.Pod {
156156 ObjectMeta : metav1.ObjectMeta {
157157 Name : "mypod" ,
158158 Namespace : "testns" ,
159159 },
160160 },
161- )
161+ ). Build ()
162162 })
163163 It ("should return an error when POD_NAME is not set" , func () {
164164 os .Unsetenv ("POD_NAME" )
@@ -185,13 +185,13 @@ var _ = Describe("Leader election", func() {
185185 client crclient.Client
186186 )
187187 BeforeEach (func () {
188- client = fake .NewFakeClient (
188+ client = fake .NewClientBuilder (). WithObjects (
189189 & corev1.Node {
190190 ObjectMeta : metav1.ObjectMeta {
191191 Name : "mynode" ,
192192 },
193193 },
194- )
194+ ). Build ()
195195 })
196196 It ("should return an error if no node is found" , func () {
197197 node := corev1.Node {}
@@ -226,33 +226,33 @@ var _ = Describe("Leader election", func() {
226226 })
227227
228228 It ("should return false if node is invalid" , func () {
229- client = fake .NewFakeClient ()
229+ client = fake .NewClientBuilder (). WithObjects (). Build ()
230230 ret := isNotReadyNode (context .TODO (), client , "" )
231231 Expect (ret ).To (Equal (false ))
232232 })
233233 It ("should return false if no NodeCondition is found" , func () {
234- client = fake .NewFakeClient ( node )
234+ client = fake .NewClientBuilder (). WithObjects ( node ). Build ( )
235235 ret := isNotReadyNode (context .TODO (), client , nodeName )
236236 Expect (ret ).To (Equal (false ))
237237 })
238238 It ("should return false if type is incorrect" , func () {
239239 node .Status .Conditions [0 ].Type = corev1 .NodeMemoryPressure
240240 node .Status .Conditions [0 ].Status = corev1 .ConditionFalse
241- client = fake .NewFakeClient ( node )
241+ client = fake .NewClientBuilder (). WithObjects ( node ). Build ( )
242242 ret := isNotReadyNode (context .TODO (), client , nodeName )
243243 Expect (ret ).To (Equal (false ))
244244 })
245245 It ("should return false if NodeReady's type is true" , func () {
246246 node .Status .Conditions [0 ].Type = corev1 .NodeReady
247247 node .Status .Conditions [0 ].Status = corev1 .ConditionTrue
248- client = fake .NewFakeClient ( node )
248+ client = fake .NewClientBuilder (). WithObjects ( node ). Build ( )
249249 ret := isNotReadyNode (context .TODO (), client , nodeName )
250250 Expect (ret ).To (Equal (false ))
251251 })
252252 It ("should return true when Type is set and Status is set to false" , func () {
253253 node .Status .Conditions [0 ].Type = corev1 .NodeReady
254254 node .Status .Conditions [0 ].Status = corev1 .ConditionFalse
255- client = fake .NewFakeClient ( node )
255+ client = fake .NewClientBuilder (). WithObjects ( node ). Build ( )
256256 ret := isNotReadyNode (context .TODO (), client , nodeName )
257257 Expect (ret ).To (Equal (true ))
258258 })
@@ -292,27 +292,27 @@ var _ = Describe("Leader election", func() {
292292 }
293293 })
294294 It ("should return an error if existing is not found" , func () {
295- client = fake .NewFakeClient ( pod )
295+ client = fake .NewClientBuilder (). WithObjects ( pod ). Build ( )
296296 err := deleteLeader (context .TODO (), client , pod , configmap )
297297 Expect (err ).ShouldNot (BeNil ())
298298 })
299299 It ("should return an error if pod is not found" , func () {
300- client = fake .NewFakeClient ( configmap )
300+ client = fake .NewClientBuilder (). WithObjects ( configmap ). Build ( )
301301 err := deleteLeader (context .TODO (), client , pod , configmap )
302302 Expect (err ).ShouldNot (BeNil ())
303303 })
304304 It ("should return an error if pod is nil" , func () {
305- client = fake .NewFakeClient ( pod , configmap )
305+ client = fake .NewClientBuilder (). WithObjects ( pod , configmap ). Build ( )
306306 err := deleteLeader (context .TODO (), client , nil , configmap )
307307 Expect (err ).ShouldNot (BeNil ())
308308 })
309309 It ("should return an error if configmap is nil" , func () {
310- client = fake .NewFakeClient ( pod , configmap )
310+ client = fake .NewClientBuilder (). WithObjects ( pod , configmap ). Build ( )
311311 err := deleteLeader (context .TODO (), client , pod , nil )
312312 Expect (err ).ShouldNot (BeNil ())
313313 })
314314 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 ( )
316316 err := deleteLeader (context .TODO (), client , pod , configmap )
317317 Expect (err ).Should (BeNil ())
318318 })
0 commit comments