Skip to content

Commit

Permalink
add uint test
Browse files Browse the repository at this point in the history
  • Loading branch information
郑力升 committed Dec 12, 2023
1 parent c71441a commit 6a15315
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 5 deletions.
21 changes: 18 additions & 3 deletions core/xdsresource/lds_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,24 @@ func TestUnmarshallLDSThriftProxy(t *testing.T) {
r := tp.Routes[0]
assert.NotNil(t, r.Match)
assert.True(t, r.Match.MatchPath("method"))
for k, v := range map[string]string{"k1": "v1", "k2": "v2"} {
assert.Equal(t, v, r.Match.GetTags()[k])
}
assert.True(t, r.Match.GetTags().Match(map[string]string{
"k1": "v1",
"k2": "v2",
"k3": "prehello",
"k4": "a4",
}))
assert.True(t, r.Match.GetTags().Match(map[string]string{
"k1": "v1",
"k2": "v2",
"k3": "pre",
"k4": "a4",
}))
assert.False(t, r.Match.GetTags().Match(map[string]string{
"k1": "v1",
"k2": "v2",
"k3": "pr",
"k4": "a4",
}))
assert.NotNil(t, r.WeightedClusters)
}
f(lis.NetworkFilters[0])
Expand Down
2 changes: 1 addition & 1 deletion core/xdsresource/matcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func BuildMatchers(headers []*v3.HeaderMatcher) Matchers {
}
case *v3matcher.StringMatcher_Prefix:
if p.Prefix != "" {
ms[header.Name] = ExactMatcher(p.Prefix)
ms[header.Name] = PrefixMatcher(p.Prefix)
}
case *v3matcher.StringMatcher_SafeRegex:
// only support google re2
Expand Down
2 changes: 1 addition & 1 deletion core/xdsresource/rds_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ func TestHTTPRouteMatch_MatchPath(t *testing.T) {
type fields struct {
Path string
Prefix string
Tags map[string]string
Tags Matchers
}
type args struct {
path string
Expand Down
22 changes: 22 additions & 0 deletions core/xdsresource/testutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,28 @@ var (
},
},
},
{
Name: "k3",
HeaderMatchSpecifier: &v3routepb.HeaderMatcher_StringMatch{
StringMatch: &v3matcher.StringMatcher{
MatchPattern: &v3matcher.StringMatcher_Prefix{
Prefix: "pre",
},
},
},
},
{
Name: "k4",
HeaderMatchSpecifier: &v3routepb.HeaderMatcher_StringMatch{
StringMatch: &v3matcher.StringMatcher{
MatchPattern: &v3matcher.StringMatcher_SafeRegex{
SafeRegex: &v3matcher.RegexMatcher{
Regex: "[a-z][1-9]",
},
},
},
},
},
},
},
Route: &v3thrift_proxy.RouteAction{
Expand Down

0 comments on commit 6a15315

Please sign in to comment.