Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
util/slices: extract common ContainsString func to package
- Loading branch information
Showing
3 changed files
with
47 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// Copyright (C) 2017 ScyllaDB | ||
|
||
package slices | ||
|
||
// ContainsString returns whether value is part of array. | ||
func ContainsString(value string, array []string) bool { | ||
for _, elem := range array { | ||
if elem == value { | ||
return true | ||
} | ||
} | ||
return false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// Copyright (C) 2017 ScyllaDB | ||
|
||
package slices | ||
|
||
import ( | ||
"testing" | ||
|
||
. "github.com/onsi/ginkgo" | ||
. "github.com/onsi/ginkgo/extensions/table" | ||
. "github.com/onsi/gomega" | ||
"github.com/onsi/gomega/types" | ||
"sigs.k8s.io/controller-runtime/pkg/envtest/printer" | ||
) | ||
|
||
var _ = Describe("Slices tests", func() { | ||
DescribeTable("ContainsString", func(v string, arr []string, matcher types.GomegaMatcher) { | ||
Expect(ContainsString(v, arr)).To(matcher) | ||
}, | ||
Entry("empty", "a", []string{}, BeFalse()), | ||
Entry("contain element", "a", []string{"a", "b"}, BeTrue()), | ||
Entry("at the end", "b", []string{"a", "b"}, BeTrue()), | ||
Entry("does not contain element", "c", []string{"a", "b"}, BeFalse()), | ||
) | ||
}) | ||
|
||
func TestSlices(t *testing.T) { | ||
RegisterFailHandler(Fail) | ||
|
||
RunSpecsWithDefaultAndCustomReporters(t, | ||
"Slices Suite", | ||
[]Reporter{printer.NewlineReporter{}}) | ||
} |