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
27900114
Commit
27900114
authored
Dec 18, 2015
by
Jacob Vosmaer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move errorpage tests into their package
parent
244e1b98
Changes
11
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
47 additions
and
39 deletions
+47
-39
Makefile
Makefile
+1
-0
authorization_test.go
authorization_test.go
+2
-1
deploy_page_test.go
deploy_page_test.go
+3
-2
development_test.go
development_test.go
+2
-1
handlers_test.go
handlers_test.go
+4
-3
internal/errorpage/error_pages.go
internal/errorpage/error_pages.go
+1
-1
internal/errorpage/error_pages_test.go
internal/errorpage/error_pages_test.go
+8
-8
internal/helper/test.go
internal/helper/test.go
+4
-4
proxy_test.go
proxy_test.go
+9
-8
servefile_test.go
servefile_test.go
+9
-8
uploads_test.go
uploads_test.go
+4
-3
No files found.
Makefile
View file @
27900114
...
...
@@ -10,6 +10,7 @@ install: gitlab-workhorse
.PHONY
:
test
test
:
test/data/group/test.git clean-workhorse gitlab-workhorse
go
fmt
|
awk
'{ print "Please run go fmt"; exit 1 }'
go
test
./internal/...
go
test
coverage
:
test/data/group/test.git
...
...
authorization_test.go
View file @
27900114
...
...
@@ -2,6 +2,7 @@ package main
import
(
"./internal/api"
"./internal/helper"
"fmt"
"net/http"
"net/http/httptest"
...
...
@@ -28,7 +29,7 @@ func runPreAuthorizeHandler(t *testing.T, suffix string, url *regexp.Regexp, api
response
:=
httptest
.
NewRecorder
()
api
.
PreAuthorizeHandler
(
okHandler
,
suffix
)(
response
,
httpRequest
)
a
ssertResponseCode
(
t
,
response
,
expectedCode
)
helper
.
A
ssertResponseCode
(
t
,
response
,
expectedCode
)
return
response
}
...
...
deploy_page_test.go
View file @
27900114
package
main
import
(
"./internal/helper"
"io/ioutil"
"net/http"
"net/http/httptest"
...
...
@@ -48,6 +49,6 @@ func TestIfDeployPageExist(t *testing.T) {
}
w
.
Flush
()
a
ssertResponseCode
(
t
,
w
,
200
)
a
ssertResponseBody
(
t
,
w
,
deployPage
)
helper
.
A
ssertResponseCode
(
t
,
w
,
200
)
helper
.
A
ssertResponseBody
(
t
,
w
,
deployPage
)
}
development_test.go
View file @
27900114
package
main
import
(
"./internal/helper"
"net/http"
"net/http/httptest"
"testing"
...
...
@@ -34,5 +35,5 @@ func TestDevelopmentModeDisabled(t *testing.T) {
if
executed
{
t
.
Error
(
"The handler should not get executed"
)
}
a
ssertResponseCode
(
t
,
w
,
404
)
helper
.
A
ssertResponseCode
(
t
,
w
,
404
)
}
handlers_test.go
View file @
27900114
package
main
import
(
"./internal/helper"
"bytes"
"compress/gzip"
"fmt"
...
...
@@ -36,7 +37,7 @@ func TestGzipEncoding(t *testing.T) {
}
})(
resp
,
req
)
a
ssertResponseCode
(
t
,
resp
,
200
)
helper
.
A
ssertResponseCode
(
t
,
resp
,
200
)
}
func
TestNoEncoding
(
t
*
testing
.
T
)
{
...
...
@@ -60,7 +61,7 @@ func TestNoEncoding(t *testing.T) {
}
})(
resp
,
req
)
a
ssertResponseCode
(
t
,
resp
,
200
)
helper
.
A
ssertResponseCode
(
t
,
resp
,
200
)
}
func
TestInvalidEncoding
(
t
*
testing
.
T
)
{
...
...
@@ -76,5 +77,5 @@ func TestInvalidEncoding(t *testing.T) {
t
.
Fatal
(
"it shouldn't be executed"
)
})(
resp
,
req
)
a
ssertResponseCode
(
t
,
resp
,
500
)
helper
.
A
ssertResponseCode
(
t
,
resp
,
500
)
}
internal/errorpage/error_pages.go
View file @
27900114
package
errorpage
import
(
"../helper"
"../helper"
"fmt"
"io/ioutil"
"log"
...
...
error_pages_test.go
→
internal/errorpage/
error_pages_test.go
View file @
27900114
package
main
package
errorpage
import
(
".
/internal/errorpage
"
".
./helper
"
"fmt"
"io/ioutil"
"net/http"
...
...
@@ -26,11 +26,11 @@ func TestIfErrorPageIsPresented(t *testing.T) {
w
.
WriteHeader
(
404
)
fmt
.
Fprint
(
w
,
"Not Found"
)
})
errorpage
.
Inject
(
dir
,
h
)(
w
,
nil
)
Inject
(
dir
,
h
)(
w
,
nil
)
w
.
Flush
()
a
ssertResponseCode
(
t
,
w
,
404
)
a
ssertResponseBody
(
t
,
w
,
errorPage
)
helper
.
A
ssertResponseCode
(
t
,
w
,
404
)
helper
.
A
ssertResponseBody
(
t
,
w
,
errorPage
)
}
func
TestIfErrorPassedIfNoErrorPageIsFound
(
t
*
testing
.
T
)
{
...
...
@@ -46,9 +46,9 @@ func TestIfErrorPassedIfNoErrorPageIsFound(t *testing.T) {
w
.
WriteHeader
(
404
)
fmt
.
Fprint
(
w
,
errorResponse
)
})
errorpage
.
Inject
(
dir
,
h
)(
w
,
nil
)
Inject
(
dir
,
h
)(
w
,
nil
)
w
.
Flush
()
a
ssertResponseCode
(
t
,
w
,
404
)
a
ssertResponseBody
(
t
,
w
,
errorResponse
)
helper
.
A
ssertResponseCode
(
t
,
w
,
404
)
helper
.
A
ssertResponseBody
(
t
,
w
,
errorResponse
)
}
helpers_
test.go
→
internal/helper/
test.go
View file @
27900114
package
main
package
helper
import
(
"net/http/httptest"
"testing"
)
func
a
ssertResponseCode
(
t
*
testing
.
T
,
response
*
httptest
.
ResponseRecorder
,
expectedCode
int
)
{
func
A
ssertResponseCode
(
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
a
ssertResponseBody
(
t
*
testing
.
T
,
response
*
httptest
.
ResponseRecorder
,
expectedBody
string
)
{
func
A
ssertResponseBody
(
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
a
ssertResponseHeader
(
t
*
testing
.
T
,
response
*
httptest
.
ResponseRecorder
,
header
string
,
expectedValue
string
)
{
func
A
ssertResponseHeader
(
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
))
}
...
...
proxy_test.go
View file @
27900114
package
main
import
(
"./internal/helper"
"./internal/proxy"
"bytes"
"fmt"
...
...
@@ -44,8 +45,8 @@ func TestProxyRequest(t *testing.T) {
u
:=
newUpstream
(
ts
.
URL
,
""
)
w
:=
httptest
.
NewRecorder
()
u
.
Proxy
.
ServeHTTP
(
w
,
httpRequest
)
a
ssertResponseCode
(
t
,
w
,
202
)
a
ssertResponseBody
(
t
,
w
,
"RESPONSE"
)
helper
.
A
ssertResponseCode
(
t
,
w
,
202
)
helper
.
A
ssertResponseBody
(
t
,
w
,
"RESPONSE"
)
if
w
.
Header
()
.
Get
(
"Custom-Response-Header"
)
!=
"test"
{
t
.
Fatal
(
"Expected custom response header"
)
...
...
@@ -62,8 +63,8 @@ func TestProxyError(t *testing.T) {
u
:=
newUpstream
(
"http://localhost:655575/"
,
""
)
w
:=
httptest
.
NewRecorder
()
u
.
Proxy
.
ServeHTTP
(
w
,
httpRequest
)
a
ssertResponseCode
(
t
,
w
,
502
)
a
ssertResponseBody
(
t
,
w
,
"dial tcp: invalid port 655575"
)
helper
.
A
ssertResponseCode
(
t
,
w
,
502
)
helper
.
A
ssertResponseBody
(
t
,
w
,
"dial tcp: invalid port 655575"
)
}
func
TestProxyReadTimeout
(
t
*
testing
.
T
)
{
...
...
@@ -97,8 +98,8 @@ func TestProxyReadTimeout(t *testing.T) {
w
:=
httptest
.
NewRecorder
()
u
.
Proxy
.
ServeHTTP
(
w
,
httpRequest
)
a
ssertResponseCode
(
t
,
w
,
502
)
a
ssertResponseBody
(
t
,
w
,
"net/http: timeout awaiting response headers"
)
helper
.
A
ssertResponseCode
(
t
,
w
,
502
)
helper
.
A
ssertResponseBody
(
t
,
w
,
"net/http: timeout awaiting response headers"
)
}
func
TestProxyHandlerTimeout
(
t
*
testing
.
T
)
{
...
...
@@ -117,6 +118,6 @@ func TestProxyHandlerTimeout(t *testing.T) {
w
:=
httptest
.
NewRecorder
()
u
.
Proxy
.
ServeHTTP
(
w
,
httpRequest
)
a
ssertResponseCode
(
t
,
w
,
503
)
a
ssertResponseBody
(
t
,
w
,
"Request took too long"
)
helper
.
A
ssertResponseCode
(
t
,
w
,
503
)
helper
.
A
ssertResponseBody
(
t
,
w
,
"Request took too long"
)
}
servefile_test.go
View file @
27900114
package
main
import
(
"./internal/helper"
"bytes"
"compress/gzip"
"io/ioutil"
...
...
@@ -19,7 +20,7 @@ func TestServingNonExistingFile(t *testing.T) {
w
:=
httptest
.
NewRecorder
()
dummyUpstream
.
handleServeFile
(
&
dir
,
CacheDisabled
,
nil
)(
w
,
httpRequest
)
a
ssertResponseCode
(
t
,
w
,
404
)
helper
.
A
ssertResponseCode
(
t
,
w
,
404
)
}
func
TestServingDirectory
(
t
*
testing
.
T
)
{
...
...
@@ -32,7 +33,7 @@ func TestServingDirectory(t *testing.T) {
httpRequest
,
_
:=
http
.
NewRequest
(
"GET"
,
"/file"
,
nil
)
w
:=
httptest
.
NewRecorder
()
dummyUpstream
.
handleServeFile
(
&
dir
,
CacheDisabled
,
nil
)(
w
,
httpRequest
)
a
ssertResponseCode
(
t
,
w
,
404
)
helper
.
A
ssertResponseCode
(
t
,
w
,
404
)
}
func
TestServingMalformedUri
(
t
*
testing
.
T
)
{
...
...
@@ -41,7 +42,7 @@ func TestServingMalformedUri(t *testing.T) {
w
:=
httptest
.
NewRecorder
()
dummyUpstream
.
handleServeFile
(
&
dir
,
CacheDisabled
,
nil
)(
w
,
httpRequest
)
a
ssertResponseCode
(
t
,
w
,
404
)
helper
.
A
ssertResponseCode
(
t
,
w
,
404
)
}
func
TestExecutingHandlerWhenNoFileFound
(
t
*
testing
.
T
)
{
...
...
@@ -71,7 +72,7 @@ func TestServingTheActualFile(t *testing.T) {
w
:=
httptest
.
NewRecorder
()
dummyUpstream
.
handleServeFile
(
&
dir
,
CacheDisabled
,
nil
)(
w
,
httpRequest
)
a
ssertResponseCode
(
t
,
w
,
200
)
helper
.
A
ssertResponseCode
(
t
,
w
,
200
)
if
w
.
Body
.
String
()
!=
fileContent
{
t
.
Error
(
"We should serve the file: "
,
w
.
Body
.
String
())
}
...
...
@@ -102,15 +103,15 @@ func testServingThePregzippedFile(t *testing.T, enableGzip bool) {
w
:=
httptest
.
NewRecorder
()
dummyUpstream
.
handleServeFile
(
&
dir
,
CacheDisabled
,
nil
)(
w
,
httpRequest
)
a
ssertResponseCode
(
t
,
w
,
200
)
helper
.
A
ssertResponseCode
(
t
,
w
,
200
)
if
enableGzip
{
a
ssertResponseHeader
(
t
,
w
,
"Content-Encoding"
,
"gzip"
)
helper
.
A
ssertResponseHeader
(
t
,
w
,
"Content-Encoding"
,
"gzip"
)
if
bytes
.
Compare
(
w
.
Body
.
Bytes
(),
fileGzipContent
.
Bytes
())
!=
0
{
t
.
Error
(
"We should serve the pregzipped file"
)
}
}
else
{
a
ssertResponseCode
(
t
,
w
,
200
)
a
ssertResponseHeader
(
t
,
w
,
"Content-Encoding"
,
""
)
helper
.
A
ssertResponseCode
(
t
,
w
,
200
)
helper
.
A
ssertResponseHeader
(
t
,
w
,
"Content-Encoding"
,
""
)
if
w
.
Body
.
String
()
!=
fileContent
{
t
.
Error
(
"We should serve the file: "
,
w
.
Body
.
String
())
}
...
...
uploads_test.go
View file @
27900114
package
main
import
(
"./internal/helper"
"bytes"
"fmt"
"io"
...
...
@@ -18,7 +19,7 @@ func TestUploadTempPathRequirement(t *testing.T) {
response
:=
httptest
.
NewRecorder
()
request
:=
&
http
.
Request
{}
handleFileUploads
(
dummyUpstream
.
Proxy
)
.
ServeHTTP
(
response
,
request
)
a
ssertResponseCode
(
t
,
response
,
500
)
helper
.
A
ssertResponseCode
(
t
,
response
,
500
)
}
func
TestUploadHandlerForwardingRawData
(
t
*
testing
.
T
)
{
...
...
@@ -54,7 +55,7 @@ func TestUploadHandlerForwardingRawData(t *testing.T) {
u
:=
newUpstream
(
ts
.
URL
,
""
)
handleFileUploads
(
u
.
Proxy
)
.
ServeHTTP
(
response
,
httpRequest
)
a
ssertResponseCode
(
t
,
response
,
202
)
helper
.
A
ssertResponseCode
(
t
,
response
,
202
)
if
response
.
Body
.
String
()
!=
"RESPONSE"
{
t
.
Fatal
(
"Expected RESPONSE in response body"
)
}
...
...
@@ -129,7 +130,7 @@ func TestUploadHandlerRewritingMultiPartData(t *testing.T) {
u
:=
newUpstream
(
ts
.
URL
,
""
)
handleFileUploads
(
u
.
Proxy
)
.
ServeHTTP
(
response
,
httpRequest
)
a
ssertResponseCode
(
t
,
response
,
202
)
helper
.
A
ssertResponseCode
(
t
,
response
,
202
)
if
_
,
err
:=
os
.
Stat
(
filePath
);
!
os
.
IsNotExist
(
err
)
{
t
.
Fatal
(
"expected the file to be deleted"
)
...
...
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