terraform: Adding utility methods
This commit is contained in:
parent
bf072c5862
commit
31653fcbcb
|
@ -0,0 +1,12 @@
|
|||
package terraform
|
||||
|
||||
// strSliceContains checks if a given string is contained in a slice
|
||||
// When anybody asks why Go needs generics, here you go.
|
||||
func strSliceContains(haystack []string, needle string) bool {
|
||||
for _, s := range haystack {
|
||||
if s == needle {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
|
@ -0,0 +1,18 @@
|
|||
package terraform
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestStrSliceContains(t *testing.T) {
|
||||
if strSliceContains(nil, "foo") {
|
||||
t.Fatalf("Bad")
|
||||
}
|
||||
if strSliceContains([]string{}, "foo") {
|
||||
t.Fatalf("Bad")
|
||||
}
|
||||
if strSliceContains([]string{"bar"}, "foo") {
|
||||
t.Fatalf("Bad")
|
||||
}
|
||||
if !strSliceContains([]string{"bar", "foo"}, "foo") {
|
||||
t.Fatalf("Bad")
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue