mirror of
https://github.com/hashicorp/vault.git
synced 2025-08-15 02:57:04 +02:00
63 lines
1.1 KiB
Go
63 lines
1.1 KiB
Go
package strutil
|
|
|
|
import "testing"
|
|
|
|
func TestStrutil_EquivalentSlices(t *testing.T) {
|
|
slice1 := []string{"test1", "test2", "test3"}
|
|
slice2 := []string{"test1", "test2", "test3"}
|
|
if !EquivalentSlices(slice1, slice2) {
|
|
t.Fatalf("bad: expected a match")
|
|
}
|
|
|
|
slice2 = append(slice2, "test4")
|
|
if EquivalentSlices(slice1, slice2) {
|
|
t.Fatalf("bad: expected a mismatch")
|
|
}
|
|
}
|
|
|
|
func TestStrListContains(t *testing.T) {
|
|
haystack := []string{
|
|
"dev",
|
|
"ops",
|
|
"prod",
|
|
"root",
|
|
}
|
|
if StrListContains(haystack, "tubez") {
|
|
t.Fatalf("Bad")
|
|
}
|
|
if !StrListContains(haystack, "root") {
|
|
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")
|
|
}
|
|
}
|