vault: utility string set methods
This commit is contained in:
parent
493fbc12fc
commit
b41d2e6368
|
@ -47,3 +47,14 @@ func strListContains(haystack []string, needle string) bool {
|
|||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// strListSubset checks if a given list is a subset
|
||||
// of another set
|
||||
func strListSubset(super, sub []string) bool {
|
||||
for _, item := range sub {
|
||||
if !strListContains(super, item) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
|
|
@ -50,3 +50,34 @@ func TestStrListContains(t *testing.T) {
|
|||
t.Fatalf("Bad")
|
||||
}
|
||||
}
|
||||
|
||||
func TestStrListSubset(t *testing.T) {
|
||||
parent := []string{
|
||||
"dev",
|
||||
"ops",
|
||||
"prod",
|
||||
"root",
|
||||
}
|
||||
child := []string{
|
||||
"prod",
|
||||
"ops",
|
||||
}
|
||||
if !strListSubset(parent, child) {
|
||||
t.Fatalf("Bad")
|
||||
}
|
||||
if !strListSubset(parent, parent) {
|
||||
t.Fatalf("Bad")
|
||||
}
|
||||
if !strListSubset(child, child) {
|
||||
t.Fatalf("Bad")
|
||||
}
|
||||
if !strListSubset(child, nil) {
|
||||
t.Fatalf("Bad")
|
||||
}
|
||||
if strListSubset(child, parent) {
|
||||
t.Fatalf("Bad")
|
||||
}
|
||||
if strListSubset(nil, child) {
|
||||
t.Fatalf("Bad")
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue