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
a96c4d70
Commit
a96c4d70
authored
May 09, 2015
by
Matt Holt
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #67 from peterhellberg/redirect_test
redirect: initial test for Redirect
parents
8ea98f8c
0f9df18d
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
55 additions
and
0 deletions
+55
-0
middleware/redirect/redirect_test.go
middleware/redirect/redirect_test.go
+55
-0
No files found.
middleware/redirect/redirect_test.go
0 → 100644
View file @
a96c4d70
package
redirect
import
(
"net/http"
"net/http/httptest"
"testing"
"github.com/mholt/caddy/middleware"
)
func
TestRedirect
(
t
*
testing
.
T
)
{
for
i
,
test
:=
range
[]
struct
{
from
string
expectedLocation
string
}{
{
"/from"
,
"/to"
},
{
"/a"
,
"/b"
},
{
"/aa"
,
""
},
{
"/"
,
""
},
{
"/a?foo=bar"
,
"/b"
},
{
"/asdf?foo=bar"
,
""
},
{
"/foo#bar"
,
""
},
{
"/a#foo"
,
"/b"
},
}
{
var
nextCalled
bool
re
:=
Redirect
{
Next
:
middleware
.
HandlerFunc
(
func
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
(
int
,
error
)
{
nextCalled
=
true
return
0
,
nil
}),
Rules
:
[]
Rule
{
{
From
:
"/from"
,
To
:
"/to"
},
{
From
:
"/a"
,
To
:
"/b"
},
},
}
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
()
re
.
ServeHTTP
(
rec
,
req
)
if
rec
.
Header
()
.
Get
(
"Location"
)
!=
test
.
expectedLocation
{
t
.
Errorf
(
"Test %d: Expected Location header to be %q but was %q"
,
i
,
test
.
expectedLocation
,
rec
.
Header
()
.
Get
(
"Location"
))
}
if
nextCalled
&&
test
.
expectedLocation
!=
""
{
t
.
Errorf
(
"Test %d: Next handler was unexpectedly called"
,
i
)
}
}
}
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