@@ -58,13 +58,15 @@ var _ = Describe("Client", func() {
58
58
var pod * corev1.Pod
59
59
var node * corev1.Node
60
60
var count uint64 = 0
61
+ var replicaCount int32 = 2
61
62
var ns = "default"
62
63
63
64
BeforeEach (func (done Done ) {
64
65
atomic .AddUint64 (& count , 1 )
65
66
dep = & appsv1.Deployment {
66
67
ObjectMeta : metav1.ObjectMeta {Name : fmt .Sprintf ("deployment-name-%v" , count ), Namespace : ns },
67
68
Spec : appsv1.DeploymentSpec {
69
+ Replicas : & replicaCount ,
68
70
Selector : & metav1.LabelSelector {
69
71
MatchLabels : map [string ]string {"foo" : "bar" },
70
72
},
@@ -143,7 +145,7 @@ var _ = Describe("Client", func() {
143
145
close (done )
144
146
})
145
147
146
- It ("should use the provided Mapper if provided" , func () {
148
+ PIt ("should use the provided Mapper if provided" , func () {
147
149
148
150
})
149
151
@@ -267,7 +269,7 @@ var _ = Describe("Client", func() {
267
269
Expect (err .Error ()).To (ContainSubstring ("no kind is registered for the type" ))
268
270
})
269
271
270
- It ("should fail if the GVK cannot be mapped to a Resource" , func () {
272
+ PIt ("should fail if the GVK cannot be mapped to a Resource" , func () {
271
273
// TODO(seans3): implement these
272
274
// Example: ListOptions
273
275
})
@@ -358,11 +360,11 @@ var _ = Describe("Client", func() {
358
360
close (done )
359
361
})
360
362
361
- It ("should fail if the object does not pass server-side validation" , func () {
363
+ PIt ("should fail if the object does not pass server-side validation" , func () {
362
364
363
365
})
364
366
365
- It ("should fail if the object doesn't have meta" , func () {
367
+ PIt ("should fail if the object doesn't have meta" , func () {
366
368
367
369
})
368
370
@@ -386,7 +388,120 @@ var _ = Describe("Client", func() {
386
388
close (done )
387
389
})
388
390
389
- It ("should fail if the GVK cannot be mapped to a Resource" , func () {
391
+ PIt ("should fail if the GVK cannot be mapped to a Resource" , func () {
392
+
393
+ })
394
+ })
395
+
396
+ Describe ("StatusClient" , func () {
397
+ It ("should update status of an existing object" , func (done Done ) {
398
+ cl , err := client .New (cfg , client.Options {})
399
+ Expect (err ).NotTo (HaveOccurred ())
400
+ Expect (cl ).NotTo (BeNil ())
401
+
402
+ By ("initially creating a Deployment" )
403
+ dep , err := clientset .AppsV1 ().Deployments (ns ).Create (dep )
404
+ Expect (err ).NotTo (HaveOccurred ())
405
+
406
+ By ("updating the status of Deployment" )
407
+ dep .Status .Replicas = 1
408
+ err = cl .Status ().Update (context .TODO (), dep )
409
+ Expect (err ).NotTo (HaveOccurred ())
410
+
411
+ By ("validating updated Deployment has new status" )
412
+ actual , err := clientset .AppsV1 ().Deployments (ns ).Get (dep .Name , metav1.GetOptions {})
413
+ Expect (err ).NotTo (HaveOccurred ())
414
+ Expect (actual ).NotTo (BeNil ())
415
+ Expect (actual .Status .Replicas ).To (BeEquivalentTo (1 ))
416
+
417
+ close (done )
418
+ })
419
+
420
+ It ("should not update spec of an existing object" , func (done Done ) {
421
+ cl , err := client .New (cfg , client.Options {})
422
+ Expect (err ).NotTo (HaveOccurred ())
423
+ Expect (cl ).NotTo (BeNil ())
424
+
425
+ By ("initially creating a Deployment" )
426
+ dep , err := clientset .AppsV1 ().Deployments (ns ).Create (dep )
427
+ Expect (err ).NotTo (HaveOccurred ())
428
+
429
+ By ("updating the spec and status of Deployment" )
430
+ var rc int32 = 1
431
+ dep .Status .Replicas = 1
432
+ dep .Spec .Replicas = & rc
433
+ err = cl .Status ().Update (context .TODO (), dep )
434
+ Expect (err ).NotTo (HaveOccurred ())
435
+
436
+ By ("validating updated Deployment has new status and unchanged spec" )
437
+ actual , err := clientset .AppsV1 ().Deployments (ns ).Get (dep .Name , metav1.GetOptions {})
438
+ Expect (err ).NotTo (HaveOccurred ())
439
+ Expect (actual ).NotTo (BeNil ())
440
+ Expect (actual .Status .Replicas ).To (BeEquivalentTo (1 ))
441
+ Expect (* actual .Spec .Replicas ).To (BeEquivalentTo (replicaCount ))
442
+
443
+ close (done )
444
+ })
445
+
446
+ It ("should update an existing object non-namespace object" , func (done Done ) {
447
+ cl , err := client .New (cfg , client.Options {})
448
+ Expect (err ).NotTo (HaveOccurred ())
449
+ Expect (cl ).NotTo (BeNil ())
450
+
451
+ node , err := clientset .CoreV1 ().Nodes ().Create (node )
452
+ Expect (err ).NotTo (HaveOccurred ())
453
+
454
+ By ("updating status of the object" )
455
+ node .Status .Phase = corev1 .NodeRunning
456
+ err = cl .Status ().Update (context .TODO (), node )
457
+ Expect (err ).NotTo (HaveOccurred ())
458
+
459
+ By ("validate updated Node had new annotation" )
460
+ actual , err := clientset .CoreV1 ().Nodes ().Get (node .Name , metav1.GetOptions {})
461
+ Expect (err ).NotTo (HaveOccurred ())
462
+ Expect (actual ).NotTo (BeNil ())
463
+ Expect (actual .Status .Phase ).To (Equal (corev1 .NodeRunning ))
464
+
465
+ close (done )
466
+ })
467
+
468
+ It ("should fail if the object does not exists" , func (done Done ) {
469
+ cl , err := client .New (cfg , client.Options {})
470
+ Expect (err ).NotTo (HaveOccurred ())
471
+ Expect (cl ).NotTo (BeNil ())
472
+
473
+ By ("updating status of a non-existent object" )
474
+ err = cl .Status ().Update (context .TODO (), dep )
475
+ Expect (err ).To (HaveOccurred ())
476
+
477
+ close (done )
478
+ })
479
+
480
+ It ("should fail if the object cannot be mapped to a GVK" , func (done Done ) {
481
+ By ("creating client with empty Scheme" )
482
+ emptyScheme := runtime .NewScheme ()
483
+ cl , err := client .New (cfg , client.Options {Scheme : emptyScheme })
484
+ Expect (err ).NotTo (HaveOccurred ())
485
+ Expect (cl ).NotTo (BeNil ())
486
+
487
+ By ("initially creating a Deployment" )
488
+ dep , err := clientset .AppsV1 ().Deployments (ns ).Create (dep )
489
+ Expect (err ).NotTo (HaveOccurred ())
490
+
491
+ By ("updating status of the Deployment" )
492
+ dep .Status .Replicas = 1
493
+ err = cl .Status ().Update (context .TODO (), dep )
494
+ Expect (err ).To (HaveOccurred ())
495
+ Expect (err .Error ()).To (ContainSubstring ("no kind is registered for the type" ))
496
+
497
+ close (done )
498
+ })
499
+
500
+ PIt ("should fail if the GVK cannot be mapped to a Resource" , func () {
501
+
502
+ })
503
+
504
+ PIt ("should fail if an API does not implement Status subresource" , func () {
390
505
391
506
})
392
507
})
@@ -471,7 +586,7 @@ var _ = Describe("Client", func() {
471
586
close (done )
472
587
})
473
588
474
- It ("should fail if the object doesn't have meta" , func () {
589
+ PIt ("should fail if the object doesn't have meta" , func () {
475
590
476
591
})
477
592
@@ -494,7 +609,7 @@ var _ = Describe("Client", func() {
494
609
close (done )
495
610
})
496
611
497
- It ("should fail if the GVK cannot be mapped to a Resource" , func () {
612
+ PIt ("should fail if the GVK cannot be mapped to a Resource" , func () {
498
613
499
614
})
500
615
})
@@ -609,7 +724,7 @@ var _ = Describe("Client", func() {
609
724
close (done )
610
725
})
611
726
612
- It ("should fail if the object doesn't have meta" , func () {
727
+ PIt ("should fail if the object doesn't have meta" , func () {
613
728
614
729
})
615
730
@@ -632,7 +747,7 @@ var _ = Describe("Client", func() {
632
747
Expect (err .Error ()).To (ContainSubstring ("no kind is registered for the type" ))
633
748
})
634
749
635
- It ("should fail if the GVK cannot be mapped to a Resource" , func () {
750
+ PIt ("should fail if the GVK cannot be mapped to a Resource" , func () {
636
751
637
752
})
638
753
})
@@ -846,19 +961,19 @@ var _ = Describe("Client", func() {
846
961
close (done )
847
962
}, serverSideTimeoutSeconds )
848
963
849
- It ("should fail if it cannot get a client" , func () {
964
+ PIt ("should fail if it cannot get a client" , func () {
850
965
851
966
})
852
967
853
- It ("should fail if the object doesn't have meta" , func () {
968
+ PIt ("should fail if the object doesn't have meta" , func () {
854
969
855
970
})
856
971
857
- It ("should fail if the object cannot be mapped to a GVK" , func () {
972
+ PIt ("should fail if the object cannot be mapped to a GVK" , func () {
858
973
859
974
})
860
975
861
- It ("should fail if the GVK cannot be mapped to a Resource" , func () {
976
+ PIt ("should fail if the GVK cannot be mapped to a Resource" , func () {
862
977
863
978
})
864
979
})
0 commit comments