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
4704625e
Commit
4704625e
authored
Aug 14, 2015
by
Karthic Rao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Complete test coverage for middleware/recorder.go
parent
53c47976
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
25 additions
and
4 deletions
+25
-4
middleware/recorder_test.go
middleware/recorder_test.go
+25
-4
No files found.
middleware/recorder_test.go
View file @
4704625e
...
...
@@ -3,17 +3,38 @@ package middleware
import
(
"net/http"
"net/http/httptest"
"reflect"
"testing"
)
func
TestNewResponseRecorder
(
t
*
testing
.
T
)
{
w
:=
httptest
.
NewRecorder
()
recordRequest
:=
NewResponseRecorder
(
w
)
if
!
reflect
.
DeepEqual
(
recordRequest
.
ResponseWriter
,
w
)
{
t
.
Fatalf
(
"Expected Response writer in the Recording to be same as the one sent"
)
if
!
(
recordRequest
.
ResponseWriter
==
w
)
{
t
.
Fatalf
(
"Expected Response writer in the Recording to be same as the one sent
\n
"
)
}
if
recordRequest
.
status
!=
http
.
StatusOK
{
t
.
Fatalf
(
"Expected recorded status to be http.StatusOK"
)
t
.
Fatalf
(
"Expected recorded status to be http.StatusOK (%d) , but found %d
\n
"
,
recordRequest
.
status
)
}
}
func
TestWriteHeader
(
t
*
testing
.
T
)
{
w
:=
httptest
.
NewRecorder
()
recordRequest
:=
NewResponseRecorder
(
w
)
recordRequest
.
WriteHeader
(
401
)
if
w
.
Code
!=
401
||
recordRequest
.
status
!=
401
{
t
.
Fatalf
(
"Expected Response status to be set to 401, but found %d
\n
"
,
recordRequest
.
status
)
}
}
func
TestWrite
(
t
*
testing
.
T
)
{
w
:=
httptest
.
NewRecorder
()
responseTestString
:=
"test"
recordRequest
:=
NewResponseRecorder
(
w
)
buf
:=
[]
byte
(
responseTestString
)
recordRequest
.
Write
(
buf
)
if
recordRequest
.
size
!=
len
(
buf
)
{
t
.
Fatalf
(
"Expected the bytes written counter to be %d, but instead found %d
\n
"
,
len
(
buf
),
recordRequest
.
size
)
}
if
w
.
Body
.
String
()
!=
responseTestString
{
t
.
Fatalf
(
"Expected Response Body to be %s , but found %s
\n
"
,
w
.
Body
.
String
())
}
}
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