Skip to content

Commit ea24e68

Browse files
committed
Add tests for apply options
1 parent 3465059 commit ea24e68

File tree

1 file changed

+78
-0
lines changed

1 file changed

+78
-0
lines changed

pkg/client/options_test.go

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,27 @@ var _ = Describe("GetOptions", func() {
109109
})
110110
})
111111

112+
var _ = Describe("ApplyOptions", func() {
113+
It("Should set DryRun", func() {
114+
o := &client.ApplyOptions{DryRun: []string{"Hello", "Theodore"}}
115+
newApplyOpts := &client.ApplyOptions{}
116+
o.ApplyToApply(newApplyOpts)
117+
Expect(newApplyOpts).To(Equal(o))
118+
})
119+
It("Should set Force", func() {
120+
o := &client.ApplyOptions{Force: ptr.To(true)}
121+
newApplyOpts := &client.ApplyOptions{}
122+
o.ApplyToApply(newApplyOpts)
123+
Expect(newApplyOpts).To(Equal(o))
124+
})
125+
It("Should set FieldManager", func() {
126+
o := &client.ApplyOptions{FieldManager: "field-manager"}
127+
newApplyOpts := &client.ApplyOptions{}
128+
o.ApplyToApply(newApplyOpts)
129+
Expect(newApplyOpts).To(Equal(o))
130+
})
131+
})
132+
112133
var _ = Describe("CreateOptions", func() {
113134
It("Should set DryRun", func() {
114135
o := &client.CreateOptions{DryRun: []string{"Hello", "Theodore"}}
@@ -278,13 +299,70 @@ var _ = Describe("MatchingLabels", func() {
278299
})
279300
})
280301

302+
var _ = Describe("DryRunAll", func() {
303+
It("Should apply to ApplyOptions", func() {
304+
o := &client.ApplyOptions{DryRun: []string{"server"}}
305+
t := client.DryRunAll
306+
t.ApplyToApply(o)
307+
Expect(o.DryRun).To(Equal([]string{metav1.DryRunAll}))
308+
})
309+
It("Should apply to CreateOptions", func() {
310+
o := &client.CreateOptions{DryRun: []string{"server"}}
311+
t := client.DryRunAll
312+
t.ApplyToCreate(o)
313+
Expect(o.DryRun).To(Equal([]string{metav1.DryRunAll}))
314+
})
315+
It("Should apply to UpdateOptions", func() {
316+
o := &client.UpdateOptions{DryRun: []string{"server"}}
317+
t := client.DryRunAll
318+
t.ApplyToUpdate(o)
319+
Expect(o.DryRun).To(Equal([]string{metav1.DryRunAll}))
320+
})
321+
It("Should apply to PatchOptions", func() {
322+
o := &client.PatchOptions{DryRun: []string{"server"}}
323+
t := client.DryRunAll
324+
t.ApplyToPatch(o)
325+
Expect(o.DryRun).To(Equal([]string{metav1.DryRunAll}))
326+
})
327+
It("Should apply to DeleteOptions", func() {
328+
o := &client.DeleteOptions{DryRun: []string{"server"}}
329+
t := client.DryRunAll
330+
t.ApplyToDelete(o)
331+
Expect(o.DryRun).To(Equal([]string{metav1.DryRunAll}))
332+
})
333+
It("Should apply to SubResourcePatchOptions", func() {
334+
o := &client.SubResourcePatchOptions{PatchOptions: client.PatchOptions{DryRun: []string{"server"}}}
335+
t := client.DryRunAll
336+
t.ApplyToSubResourcePatch(o)
337+
Expect(o.DryRun).To(Equal([]string{metav1.DryRunAll}))
338+
})
339+
It("Should apply to SubResourceCreateOptions", func() {
340+
o := &client.SubResourceCreateOptions{CreateOptions: client.CreateOptions{DryRun: []string{"server"}}}
341+
t := client.DryRunAll
342+
t.ApplyToSubResourceCreate(o)
343+
Expect(o.DryRun).To(Equal([]string{metav1.DryRunAll}))
344+
})
345+
It("Should apply to SubResourceUpdateOptions", func() {
346+
o := &client.SubResourceUpdateOptions{UpdateOptions: client.UpdateOptions{DryRun: []string{"server"}}}
347+
t := client.DryRunAll
348+
t.ApplyToSubResourceUpdate(o)
349+
Expect(o.DryRun).To(Equal([]string{metav1.DryRunAll}))
350+
})
351+
})
352+
281353
var _ = Describe("FieldOwner", func() {
282354
It("Should apply to PatchOptions", func() {
283355
o := &client.PatchOptions{FieldManager: "bar"}
284356
t := client.FieldOwner("foo")
285357
t.ApplyToPatch(o)
286358
Expect(o.FieldManager).To(Equal("foo"))
287359
})
360+
It("Should apply to ApplyOptions", func() {
361+
o := &client.ApplyOptions{FieldManager: "bar"}
362+
t := client.FieldOwner("foo")
363+
t.ApplyToApply(o)
364+
Expect(o.FieldManager).To(Equal("foo"))
365+
})
288366
It("Should apply to CreateOptions", func() {
289367
o := &client.CreateOptions{FieldManager: "bar"}
290368
t := client.FieldOwner("foo")

0 commit comments

Comments
 (0)