mirror of
https://github.com/yusing/godoxy.git
synced 2026-04-24 17:58:45 +02:00
test(rules): add tests for glob and regex, remove old path glob test
This commit is contained in:
@@ -65,18 +65,26 @@ func TestOnCorrectness(t *testing.T) {
|
|||||||
want: false,
|
want: false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "path_exact_match",
|
name: "host_match",
|
||||||
checker: "path /example",
|
checker: "host example.com",
|
||||||
input: &http.Request{
|
input: &http.Request{
|
||||||
URL: &url.URL{Path: "/example"},
|
Host: "example.com",
|
||||||
},
|
},
|
||||||
want: true,
|
want: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "path_wildcard_match",
|
name: "host_no_match",
|
||||||
checker: "path /example/*",
|
checker: "host example.com",
|
||||||
input: &http.Request{
|
input: &http.Request{
|
||||||
URL: &url.URL{Path: "/example/123"},
|
Host: "example.org",
|
||||||
|
},
|
||||||
|
want: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "path_exact_match",
|
||||||
|
checker: "path /example",
|
||||||
|
input: &http.Request{
|
||||||
|
URL: &url.URL{Path: "/example"},
|
||||||
},
|
},
|
||||||
want: true,
|
want: true,
|
||||||
},
|
},
|
||||||
@@ -133,6 +141,46 @@ func TestOnCorrectness(t *testing.T) {
|
|||||||
},
|
},
|
||||||
want: false,
|
want: false,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "regex_match",
|
||||||
|
checker: `host regex(example\w+\.com)`,
|
||||||
|
input: &http.Request{
|
||||||
|
Host: "exampleabc.com",
|
||||||
|
},
|
||||||
|
want: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "regex_no_match",
|
||||||
|
checker: `host regex(example\w+\.com)`,
|
||||||
|
input: &http.Request{
|
||||||
|
Host: "example.org",
|
||||||
|
},
|
||||||
|
want: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "glob match",
|
||||||
|
checker: `host glob(*.example.com)`,
|
||||||
|
input: &http.Request{
|
||||||
|
Host: "abc.example.com",
|
||||||
|
},
|
||||||
|
want: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "glob no match",
|
||||||
|
checker: `host glob(*.example.com)`,
|
||||||
|
input: &http.Request{
|
||||||
|
Host: "example.com",
|
||||||
|
},
|
||||||
|
want: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "glob no match 2",
|
||||||
|
checker: `host glob(*.example.com)`,
|
||||||
|
input: &http.Request{
|
||||||
|
Host: "example.org",
|
||||||
|
},
|
||||||
|
want: false,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
tests = append(tests, genCorrectnessTestCases("header", func(k, v string) *http.Request {
|
tests = append(tests, genCorrectnessTestCases("header", func(k, v string) *http.Request {
|
||||||
@@ -175,7 +223,7 @@ func TestOnCorrectness(t *testing.T) {
|
|||||||
err := on.Parse(tt.checker)
|
err := on.Parse(tt.checker)
|
||||||
expect.NoError(t, err)
|
expect.NoError(t, err)
|
||||||
got := on.Check(Cache{}, tt.input)
|
got := on.Check(Cache{}, tt.input)
|
||||||
expect.Equal(t, tt.want, got)
|
expect.Equal(t, tt.want, got, fmt.Sprintf("expect %s to %v", tt.checker, tt.want))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user