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
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kirill Smelkov
gitlab-workhorse
Commits
c87a6d91
Commit
c87a6d91
authored
Jan 15, 2016
by
Jacob Vosmaer
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' into fix-development-mode
parents
54290c47
9530b40d
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
45 additions
and
0 deletions
+45
-0
internal/testhelper/testhelper.go
internal/testhelper/testhelper.go
+45
-0
No files found.
internal/testhelper/testhelper.go
0 → 100644
View file @
c87a6d91
package
testhelper
import
(
"log"
"net/http"
"net/http/httptest"
"regexp"
"testing"
)
func
AssertResponseCode
(
t
*
testing
.
T
,
response
*
httptest
.
ResponseRecorder
,
expectedCode
int
)
{
if
response
.
Code
!=
expectedCode
{
t
.
Fatalf
(
"for HTTP request expected to get %d, got %d instead"
,
expectedCode
,
response
.
Code
)
}
}
func
AssertResponseBody
(
t
*
testing
.
T
,
response
*
httptest
.
ResponseRecorder
,
expectedBody
string
)
{
if
response
.
Body
.
String
()
!=
expectedBody
{
t
.
Fatalf
(
"for HTTP request expected to receive %q, got %q instead as body"
,
expectedBody
,
response
.
Body
.
String
())
}
}
func
AssertResponseHeader
(
t
*
testing
.
T
,
response
*
httptest
.
ResponseRecorder
,
header
string
,
expectedValue
string
)
{
if
response
.
Header
()
.
Get
(
header
)
!=
expectedValue
{
t
.
Fatalf
(
"for HTTP request expected to receive the header %q with %q, got %q"
,
header
,
expectedValue
,
response
.
Header
()
.
Get
(
header
))
}
}
func
TestServerWithHandler
(
url
*
regexp
.
Regexp
,
handler
http
.
HandlerFunc
)
*
httptest
.
Server
{
return
httptest
.
NewServer
(
http
.
HandlerFunc
(
func
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
if
url
!=
nil
&&
!
url
.
MatchString
(
r
.
URL
.
Path
)
{
log
.
Println
(
"UPSTREAM"
,
r
.
Method
,
r
.
URL
,
"DENY"
)
w
.
WriteHeader
(
404
)
return
}
if
version
:=
r
.
Header
.
Get
(
"Gitlab-Workhorse"
);
version
==
""
{
log
.
Println
(
"UPSTREAM"
,
r
.
Method
,
r
.
URL
,
"DENY"
)
w
.
WriteHeader
(
403
)
return
}
handler
(
w
,
r
)
}))
}
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