Skip to content

Commit 05495c3

Browse files
committed
✨ CreateOptions implement CreateOption
1 parent 6b4e5de commit 05495c3

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
@@ -142,6 +142,21 @@ func (o *CreateOptions) ApplyOptions(opts []CreateOption) *CreateOptions {
142142
return o
143143
}
144144

145+
// ApplyToCreate implements CreateOption
146+
func (o *CreateOptions) ApplyToCreate(co *CreateOptions) {
147+
if o.DryRun != nil {
148+
co.DryRun = o.DryRun
149+
}
150+
if o.FieldManager != "" {
151+
co.FieldManager = o.FieldManager
152+
}
153+
if o.Raw != nil {
154+
co.Raw = o.Raw
155+
}
156+
}
157+
158+
var _ CreateOption = &CreateOptions{}
159+
145160
// CreateDryRunAll sets the "dry run" option to "all".
146161
//
147162
// Deprecated: Use DryRunAll

pkg/client/options_test.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,3 +60,30 @@ var _ = Describe("ListOptions", func() {
6060
Expect(newListOpts).To(Equal(o))
6161
})
6262
})
63+
64+
var _ = Describe("CreateOptions", func() {
65+
It("Should set DryRun", func() {
66+
o := &client.CreateOptions{DryRun: []string{"Hello", "Theodore"}}
67+
newCreatOpts := &client.CreateOptions{}
68+
o.ApplyToCreate(newCreatOpts)
69+
Expect(newCreatOpts).To(Equal(o))
70+
})
71+
It("Should set FieldManager", func() {
72+
o := &client.CreateOptions{FieldManager: "FieldManager"}
73+
newCreatOpts := &client.CreateOptions{}
74+
o.ApplyToCreate(newCreatOpts)
75+
Expect(newCreatOpts).To(Equal(o))
76+
})
77+
It("Should set Raw", func() {
78+
o := &client.CreateOptions{Raw: &metav1.CreateOptions{DryRun: []string{"Bye", "Theodore"}}}
79+
newCreatOpts := &client.CreateOptions{}
80+
o.ApplyToCreate(newCreatOpts)
81+
Expect(newCreatOpts).To(Equal(o))
82+
})
83+
It("Should not set anything", func() {
84+
o := &client.CreateOptions{}
85+
newCreatOpts := &client.CreateOptions{}
86+
o.ApplyToCreate(newCreatOpts)
87+
Expect(newCreatOpts).To(Equal(o))
88+
})
89+
})

0 commit comments

Comments
 (0)