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
d96bd526
Commit
d96bd526
authored
Sep 10, 2015
by
Matt Holt
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #235 from Karthic-Hackintosh/master
middleware: Complete test coverage for replacer
parents
f8e2cc80
ed4148f2
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
44 additions
and
1 deletion
+44
-1
config/setup/fastcgi_test.go
config/setup/fastcgi_test.go
+10
-0
middleware/browse/browse_test.go
middleware/browse/browse_test.go
+1
-1
middleware/replacer_test.go
middleware/replacer_test.go
+33
-0
No files found.
config/setup/fastcgi_test.go
View file @
d96bd526
...
@@ -51,6 +51,16 @@ func TestFastcgiParse(t *testing.T) {
...
@@ -51,6 +51,16 @@ func TestFastcgiParse(t *testing.T) {
SplitPath
:
".php"
,
SplitPath
:
".php"
,
IndexFiles
:
[]
string
{
"index.php"
},
IndexFiles
:
[]
string
{
"index.php"
},
}}},
}}},
{
`fastcgi / 127.0.0.1:9001 {
split .html
}`
,
false
,
[]
fastcgi
.
Rule
{{
Path
:
"/"
,
Address
:
"127.0.0.1:9001"
,
Ext
:
""
,
SplitPath
:
".html"
,
IndexFiles
:
[]
string
{},
}}},
}
}
for
i
,
test
:=
range
tests
{
for
i
,
test
:=
range
tests
{
c
:=
NewTestController
(
test
.
inputFastcgiConfig
)
c
:=
NewTestController
(
test
.
inputFastcgiConfig
)
...
...
middleware/browse/browse_test.go
View file @
d96bd526
package
browse
package
browse
import
(
import
(
"encoding/json"
"encoding/json"
"github.com/mholt/caddy/middleware"
"github.com/mholt/caddy/middleware"
"net/http"
"net/http"
"net/http/httptest"
"net/http/httptest"
...
...
middleware/replacer_test.go
View file @
d96bd526
...
@@ -22,6 +22,7 @@ func TestNewReplacer(t *testing.T) {
...
@@ -22,6 +22,7 @@ func TestNewReplacer(t *testing.T) {
switch
v
:=
replaceValues
.
(
type
)
{
switch
v
:=
replaceValues
.
(
type
)
{
case
replacer
:
case
replacer
:
if
v
.
replacements
[
"{host}"
]
!=
"caddyserver.com"
{
if
v
.
replacements
[
"{host}"
]
!=
"caddyserver.com"
{
t
.
Errorf
(
"Expected host to be caddyserver.com"
)
t
.
Errorf
(
"Expected host to be caddyserver.com"
)
}
}
...
@@ -36,3 +37,35 @@ func TestNewReplacer(t *testing.T) {
...
@@ -36,3 +37,35 @@ func TestNewReplacer(t *testing.T) {
t
.
Fatalf
(
"Return Value from New Replacer expected pass type assertion into a replacer type
\n
"
)
t
.
Fatalf
(
"Return Value from New Replacer expected pass type assertion into a replacer type
\n
"
)
}
}
}
}
func
TestReplace
(
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
.
Replace
(
"This host is {host}"
)
!=
"This host is caddyserver.com"
{
t
.
Errorf
(
"Expected host replacement failed"
)
}
if
v
.
Replace
(
"This request method is {method}"
)
!=
"This request method is POST"
{
t
.
Errorf
(
"Expected method replacement failed"
)
}
if
v
.
Replace
(
"The response status is {status}"
)
!=
"The response status is 200"
{
t
.
Errorf
(
"Expected status replacement failed"
)
}
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