summaryrefslogtreecommitdiff
path: root/modules/caddyhttp/matchers_test.go
diff options
context:
space:
mode:
authorMatthew Holt <mholt@users.noreply.github.com>2019-05-20 10:59:20 -0600
committerMatthew Holt <mholt@users.noreply.github.com>2019-05-20 10:59:20 -0600
commitfec7fa8bfda713e8042b9bbf9a480c7792b78c41 (patch)
tree53d86ab50ef7d15e9688c81b6618024c4243c98d /modules/caddyhttp/matchers_test.go
parent1a20fe330ecc39e8b98b5669b836f3b1b185f622 (diff)
Implement most of static file server; refactor and improve Replacer
Diffstat (limited to 'modules/caddyhttp/matchers_test.go')
-rw-r--r--modules/caddyhttp/matchers_test.go34
1 files changed, 28 insertions, 6 deletions
diff --git a/modules/caddyhttp/matchers_test.go b/modules/caddyhttp/matchers_test.go
index f23efab..c279bad 100644
--- a/modules/caddyhttp/matchers_test.go
+++ b/modules/caddyhttp/matchers_test.go
@@ -7,6 +7,8 @@ import (
"net/http/httptest"
"net/url"
"testing"
+
+ "bitbucket.org/lightcodelabs/caddy2"
)
func TestHostMatcher(t *testing.T) {
@@ -131,6 +133,26 @@ func TestPathMatcher(t *testing.T) {
input: "/other/",
expect: true,
},
+ {
+ match: matchPath{"*.ext"},
+ input: "foo.ext",
+ expect: true,
+ },
+ {
+ match: matchPath{"*.ext"},
+ input: "/foo/bar.ext",
+ expect: true,
+ },
+ {
+ match: matchPath{"/foo/*/baz"},
+ input: "/foo/bar/baz",
+ expect: true,
+ },
+ {
+ match: matchPath{"/foo/*/baz/bam"},
+ input: "/foo/bar/bam",
+ expect: false,
+ },
} {
req := &http.Request{URL: &url.URL{Path: tc.input}}
actual := tc.match.Match(req)
@@ -205,8 +227,8 @@ func TestPathREMatcher(t *testing.T) {
// set up the fake request and its Replacer
req := &http.Request{URL: &url.URL{Path: tc.input}}
- repl := NewReplacer(req, httptest.NewRecorder())
- ctx := context.WithValue(req.Context(), ReplacerCtxKey, repl)
+ repl := newReplacer(req, httptest.NewRecorder())
+ ctx := context.WithValue(req.Context(), caddy2.ReplacerCtxKey, repl)
req = req.WithContext(ctx)
actual := tc.match.Match(req)
@@ -218,7 +240,7 @@ func TestPathREMatcher(t *testing.T) {
for key, expectVal := range tc.expectRepl {
placeholder := fmt.Sprintf("{matchers.path_regexp.%s}", key)
- actualVal := repl.Replace(placeholder, "<empty>")
+ actualVal := repl.ReplaceAll(placeholder, "<empty>")
if actualVal != expectVal {
t.Errorf("Test %d [%v]: Expected placeholder {matchers.path_regexp.%s} to be '%s' but got '%s'",
i, tc.match.Pattern, key, expectVal, actualVal)
@@ -322,8 +344,8 @@ func TestHeaderREMatcher(t *testing.T) {
// set up the fake request and its Replacer
req := &http.Request{Header: tc.input, URL: new(url.URL)}
- repl := NewReplacer(req, httptest.NewRecorder())
- ctx := context.WithValue(req.Context(), ReplacerCtxKey, repl)
+ repl := newReplacer(req, httptest.NewRecorder())
+ ctx := context.WithValue(req.Context(), caddy2.ReplacerCtxKey, repl)
req = req.WithContext(ctx)
actual := tc.match.Match(req)
@@ -335,7 +357,7 @@ func TestHeaderREMatcher(t *testing.T) {
for key, expectVal := range tc.expectRepl {
placeholder := fmt.Sprintf("{matchers.header_regexp.%s}", key)
- actualVal := repl.Replace(placeholder, "<empty>")
+ actualVal := repl.ReplaceAll(placeholder, "<empty>")
if actualVal != expectVal {
t.Errorf("Test %d [%v]: Expected placeholder {matchers.header_regexp.%s} to be '%s' but got '%s'",
i, tc.match, key, expectVal, actualVal)