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
e7af23e1
Commit
e7af23e1
authored
Aug 25, 2016
by
Tw
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
log: add multiple log entry test
Signed-off-by:
Tw
<
tw19881113@gmail.com
>
parent
536daf36
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 @
e7af23e1
...
...
@@ -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