1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
package util
import (
"testing"
)
type InSliceData struct {
Slice []string
String string
InSlice bool
}
// Test data for TestStringInSlice cases.
var testdataInSlice = []struct {
Slice []string
String string
ExpectedResult bool
}{
{[]string{"a", "b", "c"}, "a", true},
{[]string{"a", "b", "c"}, "d", false},
{[]string{"a", "b", "c"}, "", false},
{[]string{}, "a", false},
{[]string{}, "", false},
}
func TestStringInSlice(t *testing.T) {
for _, example := range testdataInSlice {
actualResult := StringInSlice(example.String, example.Slice)
if actualResult != example.ExpectedResult {
t.Errorf("Expected stringInSlice result '%v' for example string='%v', slice='%v'. Instead got result '%v'.", example.ExpectedResult, example.String, example.Slice, actualResult)
}
}
}
// Test data for TestSymbolContainsWildcard cases.
var testdataSymbolContainsWildcard = []struct {
Symbol string
ExpectedResult bool
}{
{"mynamespace", false},
{"*", true},
{"any", true},
{"my*space", true},
{"*space", true},
{"myname*", true},
}
func TestSymbolContainsWildcard(t *testing.T) {
for _, example := range testdataSymbolContainsWildcard {
actualResult := SymbolContainsWildcard(example.Symbol)
if actualResult != example.ExpectedResult {
t.Errorf("Expected SymbolContainsWildcard result '%v' for example string='%v'. Instead got result '%v'.", example.ExpectedResult, example.Symbol, actualResult)
}
}
}
|