20
matcher "github.com/envoyproxy/go-control-plane/envoy/type/matcher/v3"
21
"github.com/google/go-cmp/cmp"
22
"google.golang.org/protobuf/testing/protocmp"
29
want *matcher.StringMatcher
32
func TestStringMatcherWithPrefix(t *testing.T) {
33
testCases := []testCase{
35
name: "wildcardAsRequired",
38
want: StringMatcherRegex(".+"),
44
want: &matcher.StringMatcher{
45
MatchPattern: &matcher.StringMatcher_Prefix{
46
Prefix: "abc-prefix-",
51
name: "suffix-empty-prefix",
54
want: &matcher.StringMatcher{
55
MatchPattern: &matcher.StringMatcher_Suffix{
64
want: StringMatcherRegex("abc.*-suffix"),
70
want: &matcher.StringMatcher{
71
MatchPattern: &matcher.StringMatcher_Exact{
78
for _, tc := range testCases {
79
t.Run(tc.name, func(t *testing.T) {
80
actual := StringMatcherWithPrefix(tc.v, tc.prefix)
81
if !cmp.Equal(actual, tc.want, protocmp.Transform()) {
82
t.Errorf("want %s but got %s", tc.want.String(), actual.String())
88
func TestStringMatcherRegex(t *testing.T) {
89
testCases := []testCase{
91
name: "wildcardAsRequired",
93
want: &matcher.StringMatcher{
94
MatchPattern: &matcher.StringMatcher_SafeRegex{
95
SafeRegex: &matcher.RegexMatcher{
102
name: "regexExpression",
104
want: &matcher.StringMatcher{
105
MatchPattern: &matcher.StringMatcher_SafeRegex{
106
SafeRegex: &matcher.RegexMatcher{
114
for _, tc := range testCases {
115
t.Run(tc.name, func(t *testing.T) {
116
if actual := StringMatcherRegex(tc.v); !cmp.Equal(actual, tc.want, protocmp.Transform()) {
117
t.Errorf("want %s but got %s", tc.want.String(), actual.String())
123
func TestStringMatcherPrefix(t *testing.T) {
124
testCases := []struct {
128
want *matcher.StringMatcher
134
want: &matcher.StringMatcher{
136
MatchPattern: &matcher.StringMatcher_Prefix{
145
want: &matcher.StringMatcher{
147
MatchPattern: &matcher.StringMatcher_Prefix{
154
for _, tc := range testCases {
155
t.Run(tc.name, func(t *testing.T) {
156
got := StringMatcherPrefix(tc.str, tc.ignoreCase)
157
if !cmp.Equal(got, tc.want, protocmp.Transform()) {
158
t.Errorf("want %v but got %v", tc.want, got)
164
func TestStringMatcherSuffix(t *testing.T) {
165
testCases := []struct {
169
want *matcher.StringMatcher
175
want: &matcher.StringMatcher{
177
MatchPattern: &matcher.StringMatcher_Suffix{
186
want: &matcher.StringMatcher{
188
MatchPattern: &matcher.StringMatcher_Suffix{
195
for _, tc := range testCases {
196
t.Run(tc.name, func(t *testing.T) {
197
got := StringMatcherSuffix(tc.str, tc.ignoreCase)
198
if !cmp.Equal(got, tc.want, protocmp.Transform()) {
199
t.Errorf("want %v but got %v", tc.want, got)
205
func TestStringMatcherExact(t *testing.T) {
206
testCases := []struct {
210
want *matcher.StringMatcher
216
want: &matcher.StringMatcher{
218
MatchPattern: &matcher.StringMatcher_Exact{
227
want: &matcher.StringMatcher{
229
MatchPattern: &matcher.StringMatcher_Exact{
236
for _, tc := range testCases {
237
t.Run(tc.name, func(t *testing.T) {
238
got := StringMatcherExact(tc.str, tc.ignoreCase)
239
if !cmp.Equal(got, tc.want, protocmp.Transform()) {
240
t.Errorf("want %v but got %v", tc.want, got)