@@ -255,6 +255,25 @@ var _ = Describe("Client", func() {
255
255
// TODO(seans3): implement these
256
256
// Example: ListOptions
257
257
})
258
+
259
+ Context ("with the DryRun option" , func () {
260
+ It ("should not create a new object" , func (done Done ) {
261
+ cl , err := client .New (cfg , client.Options {})
262
+ Expect (err ).NotTo (HaveOccurred ())
263
+ Expect (cl ).NotTo (BeNil ())
264
+
265
+ By ("creating the object (with DryRun)" )
266
+ err = cl .Create (context .TODO (), dep , client .CreateDryRunAll ())
267
+ Expect (err ).NotTo (HaveOccurred ())
268
+
269
+ actual , err := clientset .AppsV1 ().Deployments (ns ).Get (dep .Name , metav1.GetOptions {})
270
+ Expect (err ).To (HaveOccurred ())
271
+ Expect (errors .IsNotFound (err )).To (BeTrue ())
272
+ Expect (actual ).To (Equal (& appsv1.Deployment {}))
273
+
274
+ close (done )
275
+ })
276
+ })
258
277
})
259
278
260
279
Context ("with unstructured objects" , func () {
@@ -367,6 +386,33 @@ var _ = Describe("Client", func() {
367
386
368
387
})
369
388
389
+ Context ("with the DryRun option" , func () {
390
+ It ("should not create a new object from a go struct" , func (done Done ) {
391
+ cl , err := client .New (cfg , client.Options {})
392
+ Expect (err ).NotTo (HaveOccurred ())
393
+ Expect (cl ).NotTo (BeNil ())
394
+
395
+ By ("encoding the deployment as unstructured" )
396
+ u := & unstructured.Unstructured {}
397
+ scheme .Convert (dep , u , nil )
398
+ u .SetGroupVersionKind (schema.GroupVersionKind {
399
+ Group : "apps" ,
400
+ Kind : "Deployment" ,
401
+ Version : "v1" ,
402
+ })
403
+
404
+ By ("creating the object" )
405
+ err = cl .Create (context .TODO (), u , client .CreateDryRunAll ())
406
+ Expect (err ).NotTo (HaveOccurred ())
407
+
408
+ actual , err := clientset .AppsV1 ().Deployments (ns ).Get (dep .Name , metav1.GetOptions {})
409
+ Expect (err ).To (HaveOccurred ())
410
+ Expect (errors .IsNotFound (err )).To (BeTrue ())
411
+ Expect (actual ).To (Equal (& appsv1.Deployment {}))
412
+
413
+ close (done )
414
+ })
415
+ })
370
416
})
371
417
372
418
Describe ("Update" , func () {
@@ -1722,6 +1768,22 @@ var _ = Describe("Client", func() {
1722
1768
})
1723
1769
})
1724
1770
1771
+ Describe ("CreateOptions" , func () {
1772
+ It ("should allow setting DryRun to 'all'" , func () {
1773
+ co := & client.CreateOptions {}
1774
+ client .CreateDryRunAll ()(co )
1775
+ all := []string {metav1 .DryRunAll }
1776
+ Expect (co .AsCreateOptions ().DryRun ).To (Equal (all ))
1777
+ })
1778
+
1779
+ It ("should produce empty metav1.CreateOptions if nil" , func () {
1780
+ var co * client.CreateOptions
1781
+ Expect (co .AsCreateOptions ()).To (Equal (& metav1.CreateOptions {}))
1782
+ co = & client.CreateOptions {}
1783
+ Expect (co .AsCreateOptions ()).To (Equal (& metav1.CreateOptions {}))
1784
+ })
1785
+ })
1786
+
1725
1787
Describe ("DeleteOptions" , func () {
1726
1788
It ("should allow setting GracePeriodSeconds" , func () {
1727
1789
do := & client.DeleteOptions {}
@@ -1846,6 +1908,22 @@ var _ = Describe("Client", func() {
1846
1908
Expect (lo .Namespace ).To (Equal ("test" ))
1847
1909
})
1848
1910
})
1911
+
1912
+ Describe ("UpdateOptions" , func () {
1913
+ It ("should allow setting DryRun to 'all'" , func () {
1914
+ uo := & client.UpdateOptions {}
1915
+ client .UpdateDryRunAll ()(uo )
1916
+ all := []string {metav1 .DryRunAll }
1917
+ Expect (uo .AsUpdateOptions ().DryRun ).To (Equal (all ))
1918
+ })
1919
+
1920
+ It ("should produce empty metav1.UpdateOptions if nil" , func () {
1921
+ var co * client.UpdateOptions
1922
+ Expect (co .AsUpdateOptions ()).To (Equal (& metav1.UpdateOptions {}))
1923
+ co = & client.UpdateOptions {}
1924
+ Expect (co .AsUpdateOptions ()).To (Equal (& metav1.UpdateOptions {}))
1925
+ })
1926
+ })
1849
1927
})
1850
1928
1851
1929
var _ = Describe ("DelegatingReader" , func () {
0 commit comments