mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-30 06:54:01 +00:00
make StringSet.Delete accept multiple items
This commit is contained in:
parent
6ff26d924c
commit
5b8e38a665
@ -39,9 +39,11 @@ func (s StringSet) Insert(items ...string) {
|
||||
}
|
||||
}
|
||||
|
||||
// Delete removes item from the set.
|
||||
func (s StringSet) Delete(item string) {
|
||||
delete(s, item)
|
||||
// Delete removes all items from the set.
|
||||
func (s StringSet) Delete(items ...string) {
|
||||
for _, item := range items {
|
||||
delete(s, item)
|
||||
}
|
||||
}
|
||||
|
||||
// Has returns true iff item is contained in the set.
|
||||
|
@ -59,6 +59,29 @@ func TestStringSet(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestStringSetDeleteMultiples(t *testing.T) {
|
||||
s := StringSet{}
|
||||
s.Insert("a", "b", "c")
|
||||
if len(s) != 3 {
|
||||
t.Errorf("Expected len=3: %d", len(s))
|
||||
}
|
||||
|
||||
s.Delete("a", "c")
|
||||
if len(s) != 1 {
|
||||
t.Errorf("Expected len=1: %d", len(s))
|
||||
}
|
||||
if s.Has("a") {
|
||||
t.Errorf("Unexpected contents: %#v", s)
|
||||
}
|
||||
if s.Has("c") {
|
||||
t.Errorf("Unexpected contents: %#v", s)
|
||||
}
|
||||
if !s.Has("b") {
|
||||
t.Errorf("Missing contents: %#v", s)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func TestNewStringSet(t *testing.T) {
|
||||
s := NewStringSet("a", "b", "c")
|
||||
if len(s) != 3 {
|
||||
|
Loading…
Reference in New Issue
Block a user