feat(rules.on): support route directive

This commit is contained in:
yusing
2025-05-05 19:34:24 +08:00
parent bf32cafd90
commit 62d3d200e6
3 changed files with 59 additions and 0 deletions

View File

@@ -8,6 +8,7 @@ import (
"testing"
"github.com/yusing/go-proxy/internal/gperr"
"github.com/yusing/go-proxy/internal/net/gphttp/httpheaders"
. "github.com/yusing/go-proxy/internal/utils/testing"
"golang.org/x/crypto/bcrypt"
)
@@ -168,6 +169,22 @@ func TestParseOn(t *testing.T) {
input: "unknown",
wantErr: ErrInvalidOnTarget,
},
// route
{
name: "route_valid",
input: "route example",
wantErr: nil,
},
{
name: "route_missing_arg",
input: "route",
wantErr: ErrExpectOneArg,
},
{
name: "route_extra_arg",
input: "route example1 example2",
wantErr: ErrExpectOneArg,
},
}
for _, tt := range tests {
@@ -285,6 +302,24 @@ func TestOnCorrectness(t *testing.T) {
},
want: false,
},
{
name: "route_match",
checker: "route example",
input: &http.Request{
Header: http.Header{
httpheaders.HeaderUpstreamName: {"example"},
},
},
want: true,
},
{
name: "route_no_match",
checker: "route example",
input: &http.Request{
Header: http.Header{},
},
want: false,
},
}
tests = append(tests, genCorrectnessTestCases("header", func(k, v string) *http.Request {