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
Łukasz Nowak
caddy
Commits
bfc61824
Commit
bfc61824
authored
Aug 27, 2015
by
Matt Holt
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #225 from Karthic-Hackintosh/master
middleware: Initial test for replacer
parents
c5006321
444f9e40
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
38 additions
and
0 deletions
+38
-0
middleware/replacer_test.go
middleware/replacer_test.go
+38
-0
No files found.
middleware/replacer_test.go
0 → 100644
View file @
bfc61824
package
middleware
import
(
"net/http"
"net/http/httptest"
"strings"
"testing"
)
func
TestNewReplacer
(
t
*
testing
.
T
)
{
w
:=
httptest
.
NewRecorder
()
recordRequest
:=
NewResponseRecorder
(
w
)
userJson
:=
`{"username": "dennis"}`
reader
:=
strings
.
NewReader
(
userJson
)
//Convert string to reader
request
,
err
:=
http
.
NewRequest
(
"POST"
,
"http://caddyserver.com"
,
reader
)
//Create request with JSON body
if
err
!=
nil
{
t
.
Fatalf
(
"Request Formation Failed
\n
"
)
}
replaceValues
:=
NewReplacer
(
request
,
recordRequest
,
""
)
switch
v
:=
replaceValues
.
(
type
)
{
case
replacer
:
if
v
.
replacements
[
"{host}"
]
!=
"caddyserver.com"
{
t
.
Errorf
(
"Expected host to be caddyserver.com"
)
}
if
v
.
replacements
[
"{method}"
]
!=
"POST"
{
t
.
Errorf
(
"Expected request method to be POST"
)
}
if
v
.
replacements
[
"{status}"
]
!=
"200"
{
t
.
Errorf
(
"Expected status to be 200"
)
}
default
:
t
.
Fatalf
(
"Return Value from New Replacer expected pass type assertion into a replacer type
\n
"
)
}
}
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