mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-04 09:49:50 +00:00
Merge pull request #522 from Sarsate/has-all
Added HasAll utility method for string set.
This commit is contained in:
commit
dd36c45bfe
@ -34,7 +34,8 @@ func TestValidateVolumes(t *testing.T) {
|
|||||||
if len(errs) != 0 {
|
if len(errs) != 0 {
|
||||||
t.Errorf("expected success: %v", errs)
|
t.Errorf("expected success: %v", errs)
|
||||||
}
|
}
|
||||||
if len(names) != 4 || !names.Has("abc") || !names.Has("123") || !names.Has("abc-123") || !names.Has("empty") {
|
expectedSet := util.NewStringSet("abc", "123", "abc-123", "empty")
|
||||||
|
if len(names) != 4 || !names.HasAll(expectedSet) {
|
||||||
t.Errorf("wrong names result: %v", names)
|
t.Errorf("wrong names result: %v", names)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -50,6 +50,16 @@ func (s StringSet) Has(item string) bool {
|
|||||||
return contained
|
return contained
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// HasAll returns true iff all items are contained in the set.
|
||||||
|
func (s1 StringSet) HasAll(s2 StringSet) bool {
|
||||||
|
for item, _ := range s2 {
|
||||||
|
if !s1.Has(item) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
// List returns the contents as a sorted string slice.
|
// List returns the contents as a sorted string slice.
|
||||||
func (s StringSet) List() []string {
|
func (s StringSet) List() []string {
|
||||||
res := make([]string, 0, len(s))
|
res := make([]string, 0, len(s))
|
||||||
|
@ -23,6 +23,7 @@ import (
|
|||||||
|
|
||||||
func TestStringSet(t *testing.T) {
|
func TestStringSet(t *testing.T) {
|
||||||
s := StringSet{}
|
s := StringSet{}
|
||||||
|
s2 := StringSet{}
|
||||||
if len(s) != 0 {
|
if len(s) != 0 {
|
||||||
t.Errorf("Expected len=0: %d", len(s))
|
t.Errorf("Expected len=0: %d", len(s))
|
||||||
}
|
}
|
||||||
@ -41,6 +42,15 @@ func TestStringSet(t *testing.T) {
|
|||||||
if s.Has("a") {
|
if s.Has("a") {
|
||||||
t.Errorf("Unexpected contents: %#v", s)
|
t.Errorf("Unexpected contents: %#v", s)
|
||||||
}
|
}
|
||||||
|
s.Insert("a")
|
||||||
|
s2.Insert("a","b","d")
|
||||||
|
if s.HasAll(s2) {
|
||||||
|
t.Errorf("Unexpected contents: %#v", s)
|
||||||
|
}
|
||||||
|
s2.Delete("d")
|
||||||
|
if !s.HasAll(s2) {
|
||||||
|
t.Errorf("Missing contents: %#v", s)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestNewStringSet(t *testing.T) {
|
func TestNewStringSet(t *testing.T) {
|
||||||
|
Loading…
Reference in New Issue
Block a user