chore: remove unused parameter from util funcs; add unit test

Added the unit tests from
https://github.com/kubernetes/kubernetes/blob/master/pkg/util/slice/slice_test.go
(minus modifier tests) so we can be sure to not change behaviour.
This commit is contained in:
Max Jonas Werner
2020-07-22 09:30:23 +02:00
parent 1f13709413
commit 04848c755a
5 changed files with 73 additions and 28 deletions

View File

@@ -25,6 +25,58 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
func TestContainsString(t *testing.T) {
src := []string{"aa", "bb", "cc"}
if !ContainsString(src, "bb") {
t.Errorf("ContainsString didn't find the string as expected")
}
}
func TestRemoveString(t *testing.T) {
tests := []struct {
testName string
input []string
remove string
want []string
}{
{
testName: "Nil input slice",
input: nil,
remove: "",
want: nil,
},
{
testName: "Slice doesn't contain the string",
input: []string{"a", "ab", "cdef"},
remove: "NotPresentInSlice",
want: []string{"a", "ab", "cdef"},
},
{
testName: "All strings removed, result is nil",
input: []string{"a"},
remove: "a",
want: nil,
},
{
testName: "One string removed",
input: []string{"a", "ab", "cdef"},
remove: "ab",
want: []string{"a", "cdef"},
},
{
testName: "All(three) strings removed",
input: []string{"ab", "a", "ab", "cdef", "ab"},
remove: "ab",
want: []string{"a", "cdef"},
},
}
for _, tt := range tests {
if got := RemoveString(tt.input, tt.remove); !reflect.DeepEqual(got, tt.want) {
t.Errorf("%v: RemoveString(%v, %q) = %v WANT %v", tt.testName, tt.input, tt.remove, got, tt.want)
}
}
}
func TestGetSecretReference(t *testing.T) {
testcases := map[string]struct {
secretParams secretParamsMap