-
Notifications
You must be signed in to change notification settings - Fork 19
/
string_value_matcher_test.go
94 lines (89 loc) · 2.1 KB
/
string_value_matcher_test.go
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
package wiremock
import (
"testing"
)
func TestStringValueMatcher_AddPrefixToMatcher(t *testing.T) {
testCases := []struct {
name string
strategy ParamMatchingStrategy
value string
prefix string
expected string
}{
{
name: "EqualTo - Add prefix to the value",
strategy: ParamEqualTo,
value: "abc",
prefix: "pre_",
expected: "pre_abc",
},
{
name: "Matches - Add prefix to regex value without start anchor",
strategy: ParamMatches,
value: "abc",
prefix: "pre_",
expected: "^pre_abc",
},
{
name: "Matches - Add prefix to regex value with start anchor",
strategy: ParamMatches,
value: "^abc",
prefix: "pre_",
expected: "^pre_abc",
},
{
name: "Matches - Add prefix to regex value with end anchor",
strategy: ParamMatches,
value: "t?o?ken$",
prefix: "pre_",
expected: "^pre_t?o?ken$",
},
{
name: "Matches - Should add prefix to wildcard regex",
strategy: ParamMatches,
value: ".*",
prefix: "pre_",
expected: "^pre_.*",
},
{
name: "Matches - Should add prefix to empty regex",
strategy: ParamMatches,
value: "",
prefix: "pre_",
expected: "^pre_",
},
{
name: "DoesNotMatch - Add prefix to regex value without start anchor",
strategy: ParamDoesNotMatch,
value: "abc",
prefix: "pre_",
expected: "^pre_abc",
},
{
name: "DoesNotMatch - Add prefix to regex value with start anchor",
strategy: ParamDoesNotMatch,
value: "^abc",
prefix: "pre_",
expected: "^pre_abc",
},
{
name: "DoesNotMatch - wildcard regex",
strategy: ParamDoesNotMatch,
value: ".*",
prefix: "pre_",
expected: "^pre_.*",
},
}
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
matcher := StringValueMatcher{
strategy: tc.strategy,
value: tc.value,
}
modifiedMatcher := matcher.addPrefixToMatcher(tc.prefix)
if modifiedMatcher.(StringValueMatcher).value != tc.expected {
t.Errorf("Expected: %s, Got: %s", tc.expected, modifiedMatcher.(StringValueMatcher).value)
}
})
}
}