@@ -48,8 +48,9 @@ var _ = Describe("Fake client", func() {
48
48
Kind : "Deployment" ,
49
49
},
50
50
ObjectMeta : metav1.ObjectMeta {
51
- Name : "test-deployment" ,
52
- Namespace : "ns1" ,
51
+ Name : "test-deployment" ,
52
+ Namespace : "ns1" ,
53
+ ResourceVersion : trackerAddResourceVersion ,
53
54
},
54
55
}
55
56
dep2 = & appsv1.Deployment {
@@ -63,6 +64,7 @@ var _ = Describe("Fake client", func() {
63
64
Labels : map [string ]string {
64
65
"test-label" : "label-value" ,
65
66
},
67
+ ResourceVersion : trackerAddResourceVersion ,
66
68
},
67
69
}
68
70
cm = & corev1.ConfigMap {
@@ -71,8 +73,9 @@ var _ = Describe("Fake client", func() {
71
73
Kind : "ConfigMap" ,
72
74
},
73
75
ObjectMeta : metav1.ObjectMeta {
74
- Name : "test-cm" ,
75
- Namespace : "ns2" ,
76
+ Name : "test-cm" ,
77
+ Namespace : "ns2" ,
78
+ ResourceVersion : trackerAddResourceVersion ,
76
79
},
77
80
Data : map [string ]string {
78
81
"test-key" : "test-value" ,
@@ -190,9 +193,12 @@ var _ = Describe("Fake client", func() {
190
193
It ("should not change the submitted object if Create failed" , func () {
191
194
By ("Trying to create an existing configmap" )
192
195
submitted := cm .DeepCopy ()
196
+ submitted .ResourceVersion = ""
197
+ submittedReference := submitted .DeepCopy ()
193
198
err := cl .Create (context .Background (), submitted )
199
+ Expect (err ).ToNot (BeNil ())
194
200
Expect (apierrors .IsAlreadyExists (err )).To (BeTrue ())
195
- Expect (submitted ).To (Equal (cm ))
201
+ Expect (submitted ).To (Equal (submittedReference ))
196
202
})
197
203
198
204
It ("should error on Create with empty Name" , func () {
@@ -282,7 +288,7 @@ var _ = Describe("Fake client", func() {
282
288
err = cl .Get (context .Background (), namespacedName , obj )
283
289
Expect (err ).To (BeNil ())
284
290
Expect (obj ).To (Equal (newcm ))
285
- Expect (obj .ObjectMeta .ResourceVersion ).To (Equal ("1 " ))
291
+ Expect (obj .ObjectMeta .ResourceVersion ).To (Equal ("1000 " ))
286
292
})
287
293
288
294
It ("should allow updates with non-set ResourceVersion for a resource that allows unconditional updates" , func () {
@@ -312,7 +318,7 @@ var _ = Describe("Fake client", func() {
312
318
err = cl .Get (context .Background (), namespacedName , obj )
313
319
Expect (err ).To (BeNil ())
314
320
Expect (obj ).To (Equal (newcm ))
315
- Expect (obj .ObjectMeta .ResourceVersion ).To (Equal ("1 " ))
321
+ Expect (obj .ObjectMeta .ResourceVersion ).To (Equal ("1000 " ))
316
322
})
317
323
318
324
It ("should reject updates with non-set ResourceVersion for a resource that doesn't allow unconditional updates" , func () {
@@ -421,7 +427,7 @@ var _ = Describe("Fake client", func() {
421
427
err = cl .Get (context .Background (), namespacedName , obj )
422
428
Expect (err ).To (BeNil ())
423
429
Expect (obj ).To (Equal (cm ))
424
- Expect (obj .ObjectMeta .ResourceVersion ).To (Equal ("" ))
430
+ Expect (obj .ObjectMeta .ResourceVersion ).To (Equal (trackerAddResourceVersion ))
425
431
})
426
432
427
433
It ("should be able to Delete" , func () {
@@ -497,7 +503,7 @@ var _ = Describe("Fake client", func() {
497
503
err = cl .Get (context .Background (), namespacedName , obj )
498
504
Expect (err ).To (BeNil ())
499
505
Expect (obj ).To (Equal (cm ))
500
- Expect (obj .ObjectMeta .ResourceVersion ).To (Equal ("" ))
506
+ Expect (obj .ObjectMeta .ResourceVersion ).To (Equal (trackerAddResourceVersion ))
501
507
})
502
508
})
503
509
@@ -523,7 +529,7 @@ var _ = Describe("Fake client", func() {
523
529
err = cl .Get (context .Background (), namespacedName , obj )
524
530
Expect (err ).NotTo (HaveOccurred ())
525
531
Expect (obj .Annotations ["foo" ]).To (Equal ("bar" ))
526
- Expect (obj .ObjectMeta .ResourceVersion ).To (Equal ("1 " ))
532
+ Expect (obj .ObjectMeta .ResourceVersion ).To (Equal ("1000 " ))
527
533
})
528
534
}
529
535
@@ -552,4 +558,23 @@ var _ = Describe("Fake client", func() {
552
558
})
553
559
AssertClientBehavior ()
554
560
})
561
+
562
+ It ("should set the ResourceVersion to 999 when adding an object to the tracker" , func () {
563
+ cl := NewClientBuilder ().WithObjects (& corev1.Secret {ObjectMeta : metav1.ObjectMeta {Name : "cm" }}).Build ()
564
+
565
+ retrieved := & corev1.Secret {}
566
+ Expect (cl .Get (context .Background (), types.NamespacedName {Name : "cm" }, retrieved )).To (Succeed ())
567
+
568
+ reference := & corev1.Secret {
569
+ TypeMeta : metav1.TypeMeta {
570
+ APIVersion : "v1" ,
571
+ Kind : "Secret" ,
572
+ },
573
+ ObjectMeta : metav1.ObjectMeta {
574
+ Name : "cm" ,
575
+ ResourceVersion : "999" ,
576
+ },
577
+ }
578
+ Expect (retrieved ).To (Equal (reference ))
579
+ })
555
580
})
0 commit comments