Skip to content

Commit aafb998

Browse files
committed
✨ UpdateOptions implements UpdateOption
1 parent 5343059 commit aafb998

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

pkg/client/options.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -446,6 +446,21 @@ func (o *UpdateOptions) ApplyOptions(opts []UpdateOption) *UpdateOptions {
446446
return o
447447
}
448448

449+
var _ UpdateOption = &UpdateOptions{}
450+
451+
// ApplyToUpdate implements UpdateOption
452+
func (o *UpdateOptions) ApplyToUpdate(uo *UpdateOptions) {
453+
if o.DryRun != nil {
454+
uo.DryRun = o.DryRun
455+
}
456+
if o.FieldManager != "" {
457+
uo.FieldManager = o.FieldManager
458+
}
459+
if o.Raw != nil {
460+
uo.Raw = o.Raw
461+
}
462+
}
463+
449464
// UpdateDryRunAll sets the "dry run" option to "all".
450465
//
451466
// Deprecated: Use DryRunAll

pkg/client/options_test.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,3 +128,30 @@ var _ = Describe("DeleteOptions", func() {
128128
Expect(newDeleteOpts).To(Equal(o))
129129
})
130130
})
131+
132+
var _ = Describe("UpdateOptions", func() {
133+
It("Should set DryRun", func() {
134+
o := &client.UpdateOptions{DryRun: []string{"Bye", "Pippa"}}
135+
newUpdateOpts := &client.UpdateOptions{}
136+
o.ApplyToUpdate(newUpdateOpts)
137+
Expect(newUpdateOpts).To(Equal(o))
138+
})
139+
It("Should set FieldManager", func() {
140+
o := &client.UpdateOptions{FieldManager: "Hello Boris"}
141+
newUpdateOpts := &client.UpdateOptions{}
142+
o.ApplyToUpdate(newUpdateOpts)
143+
Expect(newUpdateOpts).To(Equal(o))
144+
})
145+
It("Should set Raw", func() {
146+
o := &client.UpdateOptions{Raw: &metav1.UpdateOptions{}}
147+
newUpdateOpts := &client.UpdateOptions{}
148+
o.ApplyToUpdate(newUpdateOpts)
149+
Expect(newUpdateOpts).To(Equal(o))
150+
})
151+
It("Should not set anything", func() {
152+
o := &client.UpdateOptions{}
153+
newUpdateOpts := &client.UpdateOptions{}
154+
o.ApplyToUpdate(newUpdateOpts)
155+
Expect(newUpdateOpts).To(Equal(o))
156+
})
157+
})

0 commit comments

Comments
 (0)