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
45ce9636
Commit
45ce9636
authored
Jun 28, 2017
by
Nick Thomas
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'gzip-assets-tests' into 'master'
Add some tests for gzipped assets See merge request !177
parents
55aea650
4912e487
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
54 additions
and
0 deletions
+54
-0
main_test.go
main_test.go
+54
-0
No files found.
main_test.go
View file @
45ce9636
...
...
@@ -2,6 +2,7 @@ package main
import
(
"bytes"
"compress/gzip"
"encoding/base64"
"encoding/json"
"fmt"
...
...
@@ -322,6 +323,59 @@ This is a static error page for code 499
assert
.
Equal
(
t
,
string
(
errorPageBody
),
body
,
"GET %q: response body"
,
resourcePath
)
}
func
TestGzipAssets
(
t
*
testing
.
T
)
{
path
:=
"/assets/static.txt"
content
:=
"asset"
require
.
NoError
(
t
,
setupStaticFile
(
path
,
content
))
buf
:=
&
bytes
.
Buffer
{}
gzipWriter
:=
gzip
.
NewWriter
(
buf
)
_
,
err
:=
gzipWriter
.
Write
([]
byte
(
content
))
require
.
NoError
(
t
,
err
)
require
.
NoError
(
t
,
gzipWriter
.
Close
())
contentGzip
:=
buf
.
String
()
require
.
NoError
(
t
,
setupStaticFile
(
path
+
".gz"
,
contentGzip
))
proxied
:=
false
ts
:=
testhelper
.
TestServerWithHandler
(
regexp
.
MustCompile
(
`.`
),
func
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
proxied
=
true
w
.
WriteHeader
(
404
)
})
defer
ts
.
Close
()
ws
:=
startWorkhorseServer
(
ts
.
URL
)
defer
ws
.
Close
()
testCases
:=
[]
struct
{
content
string
path
string
acceptEncoding
string
contentEncoding
string
}{
{
content
:
content
,
path
:
path
},
{
content
:
contentGzip
,
path
:
path
,
acceptEncoding
:
"gzip"
,
contentEncoding
:
"gzip"
},
{
content
:
contentGzip
,
path
:
path
,
acceptEncoding
:
"gzip, compress, br"
,
contentEncoding
:
"gzip"
},
{
content
:
contentGzip
,
path
:
path
,
acceptEncoding
:
"br;q=1.0, gzip;q=0.8, *;q=0.1"
,
contentEncoding
:
"gzip"
},
}
for
_
,
tc
:=
range
testCases
{
desc
:=
fmt
.
Sprintf
(
"accept-encoding: %q"
,
tc
.
acceptEncoding
)
req
,
err
:=
http
.
NewRequest
(
"GET"
,
ws
.
URL
+
tc
.
path
,
nil
)
require
.
NoError
(
t
,
err
,
desc
)
req
.
Header
.
Set
(
"Accept-Encoding"
,
tc
.
acceptEncoding
)
resp
,
err
:=
http
.
DefaultTransport
.
RoundTrip
(
req
)
require
.
NoError
(
t
,
err
,
desc
)
defer
resp
.
Body
.
Close
()
b
,
err
:=
ioutil
.
ReadAll
(
resp
.
Body
)
require
.
NoError
(
t
,
err
,
desc
)
assert
.
Equal
(
t
,
200
,
resp
.
StatusCode
,
"%s: status code"
,
desc
)
assert
.
Equal
(
t
,
tc
.
content
,
string
(
b
),
"%s: response body"
,
desc
)
assert
.
Equal
(
t
,
tc
.
contentEncoding
,
resp
.
Header
.
Get
(
"Content-Encoding"
),
"%s: response body"
,
desc
)
assert
.
False
(
t
,
proxied
,
"%s: should not have made it to backend"
,
desc
)
}
}
var
sendDataHeader
=
"Gitlab-Workhorse-Send-Data"
func
sendDataResponder
(
command
string
,
literalJSON
string
)
*
httptest
.
Server
{
...
...
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