mirror of
https://github.com/opentofu/opentofu.git
synced 2024-12-24 16:10:46 -06:00
terraform: Adding utility methods
This commit is contained in:
parent
bf072c5862
commit
31653fcbcb
12
terraform/util.go
Normal file
12
terraform/util.go
Normal file
@ -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
|
||||
}
|
18
terraform/util_test.go
Normal file
18
terraform/util_test.go
Normal file
@ -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
Block a user