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
444f9e40
Commit
444f9e40
authored
Aug 27, 2015
by
Karthic Rao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
initial test for replacer
parent
c5006321
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 @
444f9e40
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