Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-workhorse
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
1
Merge Requests
1
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
gitlab-workhorse
Commits
c7b97add
Commit
c7b97add
authored
May 05, 2017
by
Jacob Vosmaer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add tests for CountingResponseWriter
parent
ccfb11b3
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
51 additions
and
0 deletions
+51
-0
internal/helper/countingresponsewriter_test.go
internal/helper/countingresponsewriter_test.go
+51
-0
No files found.
internal/helper/countingresponsewriter_test.go
0 → 100644
View file @
c7b97add
package
helper
import
(
"bytes"
"io"
"net/http"
"testing"
"testing/iotest"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
type
testResponseWriter
struct
{
data
[]
byte
}
func
(
*
testResponseWriter
)
WriteHeader
(
int
)
{}
func
(
*
testResponseWriter
)
Header
()
http
.
Header
{
return
nil
}
func
(
trw
*
testResponseWriter
)
Write
(
p
[]
byte
)
(
int
,
error
)
{
trw
.
data
=
append
(
trw
.
data
,
p
...
)
return
len
(
p
),
nil
}
func
TestCountingResponseWriterStatus
(
t
*
testing
.
T
)
{
crw
:=
NewCountingResponseWriter
(
&
testResponseWriter
{})
crw
.
WriteHeader
(
123
)
crw
.
WriteHeader
(
456
)
assert
.
Equal
(
t
,
123
,
crw
.
Status
())
}
func
TestCountingResponseWriterCount
(
t
*
testing
.
T
)
{
crw
:=
NewCountingResponseWriter
(
&
testResponseWriter
{})
for
_
,
n
:=
range
[]
int
{
1
,
2
,
4
,
8
,
16
,
32
}
{
_
,
err
:=
crw
.
Write
(
bytes
.
Repeat
([]
byte
{
'.'
},
n
))
require
.
NoError
(
t
,
err
)
}
assert
.
Equal
(
t
,
int64
(
63
),
crw
.
Count
())
}
func
TestCountingResponseWriterWrite
(
t
*
testing
.
T
)
{
trw
:=
&
testResponseWriter
{}
crw
:=
NewCountingResponseWriter
(
trw
)
testData
:=
[]
byte
(
"test data"
)
_
,
err
:=
io
.
Copy
(
crw
,
iotest
.
OneByteReader
(
bytes
.
NewReader
(
testData
)))
require
.
NoError
(
t
,
err
)
assert
.
Equal
(
t
,
string
(
testData
),
string
(
trw
.
data
))
}
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