Skip to content
GitLab
Next
Menu
Why GitLab
Pricing
Contact Sales
Explore
Why GitLab
Pricing
Contact Sales
Explore
Sign in
Get free trial
Primary navigation
Search or go to…
Project
gitlab-workhorse
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Privacy statement
Keyboard shortcuts
?
What's new
4
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
GitLab.org
gitlab-workhorse
Merge requests
!177
Add some tests for gzipped assets
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
Add some tests for gzipped assets
gzip-assets-tests
into
master
Overview
1
Commits
1
Pipelines
2
Changes
1
Merged
Jacob Vosmaer
requested to merge
gzip-assets-tests
into
master
7 years ago
Overview
1
Commits
1
Pipelines
2
Changes
1
Expand
This feature had no test coverage until now I think.
0
0
Merge request reports
Compare
master
version 1
698d60a7
7 years ago
master (base)
and
latest version
latest version
4912e487
1 commit,
7 years ago
version 1
698d60a7
1 commit,
7 years ago
1 file
+
54
−
0
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
main_test.go
+
54
−
0
Options
@@ -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
{
Loading