mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-29 06:27:05 +00:00
add StringSet.HasAny
This commit is contained in:
parent
8fa21ebd62
commit
f258717f26
@ -75,6 +75,16 @@ func (s StringSet) HasAll(items ...string) bool {
|
||||
return true
|
||||
}
|
||||
|
||||
// HasAny returns true if any items are contained in the set.
|
||||
func (s StringSet) HasAny(items ...string) bool {
|
||||
for _, item := range items {
|
||||
if s.Has(item) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// Difference returns a set of objects that are not in s2
|
||||
// For example:
|
||||
// s1 = {1, 2, 3}
|
||||
|
@ -117,3 +117,15 @@ func TestStringSetDifference(t *testing.T) {
|
||||
t.Errorf("Unexpected contents: %#v", d.List())
|
||||
}
|
||||
}
|
||||
|
||||
func TestStringSetHasAny(t *testing.T) {
|
||||
a := NewStringSet("1", "2", "3")
|
||||
|
||||
if !a.HasAny("1", "4") {
|
||||
t.Errorf("expected true, got false")
|
||||
}
|
||||
|
||||
if a.HasAny("0", "4") {
|
||||
t.Errorf("expected false, got true")
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user