support higress rewrite annotaton (#278)

This commit is contained in:
澄潭
2023-04-07 17:59:13 +08:00
committed by GitHub
parent 96e7153c8c
commit acaf3d899a
2 changed files with 106 additions and 4 deletions

View File

@@ -124,6 +124,14 @@ func TestRewriteParse(t *testing.T) {
RewriteHost: "test.com",
},
},
{
input: Annotations{
buildHigressAnnotationKey(rewritePath): "/test",
},
expect: &RewriteConfig{
RewritePath: "/test",
},
},
}
for _, testCase := range testCases {
@@ -241,6 +249,87 @@ func TestRewriteApplyRoute(t *testing.T) {
},
},
},
{
config: &Ingress{
Rewrite: &RewriteConfig{
RewriteTarget: "/test",
RewritePath: "/test",
RewriteHost: "test.com",
},
},
input: &networking.HTTPRoute{
Match: []*networking.HTTPMatchRequest{
{
Uri: &networking.StringMatch{
MatchType: &networking.StringMatch_Regex{
Regex: "/hello",
},
},
},
},
},
expect: &networking.HTTPRoute{
Match: []*networking.HTTPMatchRequest{
{
Uri: &networking.StringMatch{
MatchType: &networking.StringMatch_Regex{
Regex: "/hello",
},
},
},
},
Rewrite: &networking.HTTPRewrite{
Uri: "/test",
Authority: "test.com",
},
},
},
{
config: &Ingress{
Rewrite: &RewriteConfig{
RewritePath: "/test",
},
},
input: &networking.HTTPRoute{
Match: []*networking.HTTPMatchRequest{
{
Uri: &networking.StringMatch{
MatchType: &networking.StringMatch_Prefix{
Prefix: "/hello/",
},
},
},
{
Uri: &networking.StringMatch{
MatchType: &networking.StringMatch_Exact{
Exact: "/hello",
},
},
},
},
},
expect: &networking.HTTPRoute{
Match: []*networking.HTTPMatchRequest{
{
Uri: &networking.StringMatch{
MatchType: &networking.StringMatch_Prefix{
Prefix: "/hello/",
},
},
},
{
Uri: &networking.StringMatch{
MatchType: &networking.StringMatch_Exact{
Exact: "/hello",
},
},
},
},
Rewrite: &networking.HTTPRewrite{
Uri: "/test/",
},
},
},
}
for _, inputCase := range inputCases {