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
fd300845
Commit
fd300845
authored
Aug 24, 2016
by
Matt Holt
Committed by
GitHub
Aug 24, 2016
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1068 from tw4452852/multiple_log_test
log: add multiple log entry test
parents
536daf36
e7af23e1
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
46 additions
and
0 deletions
+46
-0
caddyhttp/log/log_test.go
caddyhttp/log/log_test.go
+46
-0
No files found.
caddyhttp/log/log_test.go
View file @
fd300845
...
...
@@ -121,3 +121,49 @@ func TestLogRequestBody(t *testing.T) {
}
}
}
func
TestMultiEntries
(
t
*
testing
.
T
)
{
var
(
got1
bytes
.
Buffer
got2
bytes
.
Buffer
)
logger
:=
Logger
{
Rules
:
[]
*
Rule
{{
PathScope
:
"/"
,
Entries
:
[]
*
Entry
{
{
Format
:
"foo {request_body}"
,
Log
:
log
.
New
(
&
got1
,
""
,
0
),
},
{
Format
:
"{method} {request_body}"
,
Log
:
log
.
New
(
&
got2
,
""
,
0
),
},
},
}},
Next
:
httpserver
.
HandlerFunc
(
func
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
(
int
,
error
)
{
// drain up body
ioutil
.
ReadAll
(
r
.
Body
)
return
0
,
nil
}),
}
r
,
err
:=
http
.
NewRequest
(
"POST"
,
"/"
,
bytes
.
NewBufferString
(
"hello world"
))
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
r
.
Header
.
Set
(
"Content-Type"
,
"application/json"
)
status
,
err
:=
logger
.
ServeHTTP
(
httptest
.
NewRecorder
(),
r
)
if
status
!=
0
{
t
.
Errorf
(
"Expected status to be 0, but was %d"
,
status
)
}
if
err
!=
nil
{
t
.
Errorf
(
"Expected error to be nil, instead got: %v"
,
err
)
}
if
got
,
expect
:=
got1
.
String
(),
"foo hello world
\n
"
;
got
!=
expect
{
t
.
Errorf
(
"Expected %q, but got %q"
,
expect
,
got
)
}
if
got
,
expect
:=
got2
.
String
(),
"POST hello world
\n
"
;
got
!=
expect
{
t
.
Errorf
(
"Expected %q, but got %q"
,
expect
,
got
)
}
}
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