Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
caddy
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
caddy
Commits
b2ee6638
Commit
b2ee6638
authored
May 07, 2015
by
Matthew Holt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Tests for rewrite middleware
parent
557410ff
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
53 additions
and
0 deletions
+53
-0
middleware/rewrite/rewrite_test.go
middleware/rewrite/rewrite_test.go
+53
-0
No files found.
middleware/rewrite/rewrite_test.go
0 → 100644
View file @
b2ee6638
package
rewrite
import
(
"fmt"
"net/http"
"net/http/httptest"
"testing"
"github.com/mholt/caddy/middleware"
)
func
TestRewrite
(
t
*
testing
.
T
)
{
rw
:=
Rewrite
{
Next
:
middleware
.
HandlerFunc
(
urlPrinter
),
Rules
:
[]
Rule
{
{
From
:
"/from"
,
To
:
"/to"
},
{
From
:
"/a"
,
To
:
"/b"
},
},
}
tests
:=
[]
struct
{
from
string
expectedTo
string
}{
{
"/from"
,
"/to"
},
{
"/a"
,
"/b"
},
{
"/aa"
,
"/aa"
},
{
"/"
,
"/"
},
{
"/a?foo=bar"
,
"/b?foo=bar"
},
{
"/asdf?foo=bar"
,
"/asdf?foo=bar"
},
{
"/foo#bar"
,
"/foo#bar"
},
{
"/a#foo"
,
"/b#foo"
},
}
for
i
,
test
:=
range
tests
{
req
,
err
:=
http
.
NewRequest
(
"GET"
,
test
.
from
,
nil
)
if
err
!=
nil
{
t
.
Fatalf
(
"Test %d: Could not create HTTP request: %v"
,
i
,
err
)
}
rec
:=
httptest
.
NewRecorder
()
rw
.
ServeHTTP
(
rec
,
req
)
if
rec
.
Body
.
String
()
!=
test
.
expectedTo
{
t
.
Errorf
(
"Test %d: Expected URL to be '%s' but was '%s'"
,
i
,
test
.
expectedTo
,
rec
.
Body
.
String
())
}
}
}
func
urlPrinter
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
(
int
,
error
)
{
fmt
.
Fprintf
(
w
,
r
.
URL
.
String
())
return
0
,
nil
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment