mirror of
https://github.com/yusing/godoxy.git
synced 2026-04-25 10:18:59 +02:00
feat(rules.on): support route directive
This commit is contained in:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user