Skip to content

Commit 714c82a

Browse files
authored
Merge pull request #6558 from thaJeztah/opts_deprecate_delete
opts: deprecate ListOpts.Delete()
2 parents aec24ba + 193db8e commit 714c82a

File tree

2 files changed

+8
-11
lines changed

2 files changed

+8
-11
lines changed

opts/opts.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ func (opts *ListOpts) Set(value string) error {
6161
}
6262

6363
// Delete removes the specified element from the slice.
64+
//
65+
// Deprecated: this method is no longer used and will be removed in the next release.
6466
func (opts *ListOpts) Delete(key string) {
6567
for i, k := range *opts.values {
6668
if k == key {

opts/opts_test.go

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -141,15 +141,11 @@ func TestListOptsWithoutValidator(t *testing.T) {
141141
if o.Get("baz") {
142142
t.Error(`o.Get("baz") == true`)
143143
}
144-
o.Delete("foo")
145-
if o.String() != "[bar bar]" {
146-
t.Errorf("%s != [bar bar]", o.String())
144+
if listOpts := o.GetSlice(); len(listOpts) != 3 || listOpts[0] != "foo" || listOpts[1] != "bar" || listOpts[2] != "bar" {
145+
t.Errorf("Expected [[foo bar bar]], got [%v]", listOpts)
147146
}
148-
if listOpts := o.GetSlice(); len(listOpts) != 2 || listOpts[0] != "bar" || listOpts[1] != "bar" {
149-
t.Errorf("Expected [[bar bar]], got [%v]", listOpts)
150-
}
151-
if mapListOpts := o.GetMap(); len(mapListOpts) != 1 {
152-
t.Errorf("Expected [map[bar:{}]], got [%v]", mapListOpts)
147+
if mapListOpts := o.GetMap(); len(mapListOpts) != 2 {
148+
t.Errorf("Expected [map[bar:{} foo:{}]], got [%v]", mapListOpts)
153149
}
154150
}
155151

@@ -182,9 +178,8 @@ func TestListOptsWithValidator(t *testing.T) {
182178
if o.Get("baz") {
183179
t.Error(`o.Get("baz") == true`)
184180
}
185-
o.Delete("valid-option2=2")
186-
if o.String() != "" {
187-
t.Errorf(`%s != ""`, o.String())
181+
if expected := "[valid-option2=2]"; o.String() != expected {
182+
t.Errorf(`%s != %q`, o.String(), expected)
188183
}
189184
}
190185

0 commit comments

Comments
 (0)