From 136c9e112c056e04e916444c5e314e8bf83c95df Mon Sep 17 00:00:00 2001 From: Danny Jones Date: Fri, 18 Jul 2014 13:53:36 -0700 Subject: [PATCH] Renames HasAll to IsSuperset; HasAll uses slice. For the pedants. HasAll is now called IsSuperset and the new HasAll method takes a slice instead of a set. --- pkg/api/validation_test.go | 3 +-- pkg/util/set.go | 12 +++++++++++- pkg/util/set_test.go | 10 ++++++++-- 3 files changed, 20 insertions(+), 5 deletions(-) diff --git a/pkg/api/validation_test.go b/pkg/api/validation_test.go index 38d689b7773..8414eaea601 100644 --- a/pkg/api/validation_test.go +++ b/pkg/api/validation_test.go @@ -34,8 +34,7 @@ func TestValidateVolumes(t *testing.T) { if len(errs) != 0 { t.Errorf("expected success: %v", errs) } - expectedSet := util.NewStringSet("abc", "123", "abc-123", "empty") - if len(names) != 4 || !names.HasAll(expectedSet) { + if len(names) != 4 || !names.HasAll("abc", "123", "abc-123", "empty") { t.Errorf("wrong names result: %v", names) } diff --git a/pkg/util/set.go b/pkg/util/set.go index de49cd59bbb..590b34b3ea0 100644 --- a/pkg/util/set.go +++ b/pkg/util/set.go @@ -51,7 +51,17 @@ func (s StringSet) Has(item string) bool { } // HasAll returns true iff all items are contained in the set. -func (s1 StringSet) HasAll(s2 StringSet) bool { +func (s StringSet) HasAll(items ...string) bool { + for _, item := range items { + if !s.Has(item) { + return false + } + } + return true +} + +// IsSuperset returns true iff s1 is a superset of s2. +func (s1 StringSet) IsSuperset(s2 StringSet) bool { for item, _ := range s2 { if !s1.Has(item) { return false diff --git a/pkg/util/set_test.go b/pkg/util/set_test.go index 9ceb8b8326d..601988f8a73 100644 --- a/pkg/util/set_test.go +++ b/pkg/util/set_test.go @@ -43,12 +43,18 @@ func TestStringSet(t *testing.T) { t.Errorf("Unexpected contents: %#v", s) } s.Insert("a") + if s.HasAll("a","b","d") { + t.Errorf("Unexpected contents: %#v", s) + } + if !s.HasAll("a","b",) { + t.Errorf("Missing contents: %#v", s) + } s2.Insert("a","b","d") - if s.HasAll(s2) { + if s.IsSuperset(s2) { t.Errorf("Unexpected contents: %#v", s) } s2.Delete("d") - if !s.HasAll(s2) { + if !s.IsSuperset(s2) { t.Errorf("Missing contents: %#v", s) } }