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
b9409540
Commit
b9409540
authored
Dec 17, 2015
by
Jacob Vosmaer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use dummyUpstream variable
parent
69872685
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
8 additions
and
6 deletions
+8
-6
servefile_test.go
servefile_test.go
+8
-6
No files found.
servefile_test.go
View file @
b9409540
...
@@ -11,12 +11,14 @@ import (
...
@@ -11,12 +11,14 @@ import (
"testing"
"testing"
)
)
var
dummyUpstream
=
newUpstream
(
"http://localhost"
,
nil
)
func
TestServingNonExistingFile
(
t
*
testing
.
T
)
{
func
TestServingNonExistingFile
(
t
*
testing
.
T
)
{
dir
:=
"/path/to/non/existing/directory"
dir
:=
"/path/to/non/existing/directory"
httpRequest
,
_
:=
http
.
NewRequest
(
"GET"
,
"/file"
,
nil
)
httpRequest
,
_
:=
http
.
NewRequest
(
"GET"
,
"/file"
,
nil
)
w
:=
httptest
.
NewRecorder
()
w
:=
httptest
.
NewRecorder
()
newUpstream
(
"http://localhost"
,
nil
)
.
handleServeFile
(
&
dir
,
CacheDisabled
,
nil
)(
w
,
httpRequest
)
dummyUpstream
.
handleServeFile
(
&
dir
,
CacheDisabled
,
nil
)(
w
,
httpRequest
)
assertResponseCode
(
t
,
w
,
404
)
assertResponseCode
(
t
,
w
,
404
)
}
}
...
@@ -29,7 +31,7 @@ func TestServingDirectory(t *testing.T) {
...
@@ -29,7 +31,7 @@ func TestServingDirectory(t *testing.T) {
httpRequest
,
_
:=
http
.
NewRequest
(
"GET"
,
"/file"
,
nil
)
httpRequest
,
_
:=
http
.
NewRequest
(
"GET"
,
"/file"
,
nil
)
w
:=
httptest
.
NewRecorder
()
w
:=
httptest
.
NewRecorder
()
newUpstream
(
"http://localhost"
,
nil
)
.
handleServeFile
(
&
dir
,
CacheDisabled
,
nil
)(
w
,
httpRequest
)
dummyUpstream
.
handleServeFile
(
&
dir
,
CacheDisabled
,
nil
)(
w
,
httpRequest
)
assertResponseCode
(
t
,
w
,
404
)
assertResponseCode
(
t
,
w
,
404
)
}
}
...
@@ -38,7 +40,7 @@ func TestServingMalformedUri(t *testing.T) {
...
@@ -38,7 +40,7 @@ func TestServingMalformedUri(t *testing.T) {
httpRequest
,
_
:=
http
.
NewRequest
(
"GET"
,
"/../../../static/file"
,
nil
)
httpRequest
,
_
:=
http
.
NewRequest
(
"GET"
,
"/../../../static/file"
,
nil
)
w
:=
httptest
.
NewRecorder
()
w
:=
httptest
.
NewRecorder
()
newUpstream
(
"http://localhost"
,
nil
)
.
handleServeFile
(
&
dir
,
CacheDisabled
,
nil
)(
w
,
httpRequest
)
dummyUpstream
.
handleServeFile
(
&
dir
,
CacheDisabled
,
nil
)(
w
,
httpRequest
)
assertResponseCode
(
t
,
w
,
404
)
assertResponseCode
(
t
,
w
,
404
)
}
}
...
@@ -47,7 +49,7 @@ func TestExecutingHandlerWhenNoFileFound(t *testing.T) {
...
@@ -47,7 +49,7 @@ func TestExecutingHandlerWhenNoFileFound(t *testing.T) {
httpRequest
,
_
:=
http
.
NewRequest
(
"GET"
,
"/file"
,
nil
)
httpRequest
,
_
:=
http
.
NewRequest
(
"GET"
,
"/file"
,
nil
)
executed
:=
false
executed
:=
false
newUpstream
(
"http://localhost"
,
nil
)
.
handleServeFile
(
&
dir
,
CacheDisabled
,
func
(
_
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
dummyUpstream
.
handleServeFile
(
&
dir
,
CacheDisabled
,
func
(
_
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
executed
=
(
r
==
httpRequest
)
executed
=
(
r
==
httpRequest
)
})(
nil
,
httpRequest
)
})(
nil
,
httpRequest
)
if
!
executed
{
if
!
executed
{
...
@@ -68,7 +70,7 @@ func TestServingTheActualFile(t *testing.T) {
...
@@ -68,7 +70,7 @@ func TestServingTheActualFile(t *testing.T) {
ioutil
.
WriteFile
(
filepath
.
Join
(
dir
,
"file"
),
[]
byte
(
fileContent
),
0600
)
ioutil
.
WriteFile
(
filepath
.
Join
(
dir
,
"file"
),
[]
byte
(
fileContent
),
0600
)
w
:=
httptest
.
NewRecorder
()
w
:=
httptest
.
NewRecorder
()
newUpstream
(
"http://localhost"
,
nil
)
.
handleServeFile
(
&
dir
,
CacheDisabled
,
nil
)(
w
,
httpRequest
)
dummyUpstream
.
handleServeFile
(
&
dir
,
CacheDisabled
,
nil
)(
w
,
httpRequest
)
assertResponseCode
(
t
,
w
,
200
)
assertResponseCode
(
t
,
w
,
200
)
if
w
.
Body
.
String
()
!=
fileContent
{
if
w
.
Body
.
String
()
!=
fileContent
{
t
.
Error
(
"We should serve the file: "
,
w
.
Body
.
String
())
t
.
Error
(
"We should serve the file: "
,
w
.
Body
.
String
())
...
@@ -99,7 +101,7 @@ func testServingThePregzippedFile(t *testing.T, enableGzip bool) {
...
@@ -99,7 +101,7 @@ func testServingThePregzippedFile(t *testing.T, enableGzip bool) {
ioutil
.
WriteFile
(
filepath
.
Join
(
dir
,
"file"
),
[]
byte
(
fileContent
),
0600
)
ioutil
.
WriteFile
(
filepath
.
Join
(
dir
,
"file"
),
[]
byte
(
fileContent
),
0600
)
w
:=
httptest
.
NewRecorder
()
w
:=
httptest
.
NewRecorder
()
newUpstream
(
"http://localhost"
,
nil
)
.
handleServeFile
(
&
dir
,
CacheDisabled
,
nil
)(
w
,
httpRequest
)
dummyUpstream
.
handleServeFile
(
&
dir
,
CacheDisabled
,
nil
)(
w
,
httpRequest
)
assertResponseCode
(
t
,
w
,
200
)
assertResponseCode
(
t
,
w
,
200
)
if
enableGzip
{
if
enableGzip
{
assertResponseHeader
(
t
,
w
,
"Content-Encoding"
,
"gzip"
)
assertResponseHeader
(
t
,
w
,
"Content-Encoding"
,
"gzip"
)
...
...
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