Skip to content

Commit

Permalink
test: Add tests for compress
Browse files Browse the repository at this point in the history
  • Loading branch information
oxyno-zeta committed Mar 8, 2021
1 parent 097c776 commit 92387ac
Show file tree
Hide file tree
Showing 2 changed files with 132 additions and 0 deletions.
119 changes: 119 additions & 0 deletions pkg/s3-proxy/server/server_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (

func TestPublicRouter(t *testing.T) {
trueValue := true
falseValue := false
accessKey := "YOUR-ACCESSKEYID"
secretAccessKey := "YOUR-SECRETACCESSKEY"
region := "eu-central-1"
Expand Down Expand Up @@ -67,6 +68,7 @@ func TestPublicRouter(t *testing.T) {
inputBody string
inputFileName string
inputFileKey string
inputHeaders map[string]string
expectedCode int
expectedBody string
expectedHeaders map[string]string
Expand Down Expand Up @@ -270,6 +272,115 @@ func TestPublicRouter(t *testing.T) {
"Content-Type": "text/plain; charset=utf-8",
},
},
{
name: "GET a file with success with compress enabled",
args: args{
cfg: &config.Config{
Server: svrCfg,
ListTargets: &config.ListTargetsConfig{},
Tracing: tracingConfig,
Templates: &config.TemplateConfig{
FolderList: "../../../templates/folder-list.tpl",
TargetList: "../../../templates/target-list.tpl",
NotFound: "../../../templates/not-found.tpl",
Forbidden: "../../../templates/forbidden.tpl",
BadRequest: "../../../templates/bad-request.tpl",
InternalServerError: "../../../templates/internal-server-error.tpl",
Unauthorized: "../../../templates/unauthorized.tpl",
},
Targets: []*config.TargetConfig{
{
Name: "target1",
Bucket: &config.BucketConfig{
Name: bucket,
Region: region,
S3Endpoint: s3server.URL,
Credentials: &config.BucketCredentialConfig{
AccessKey: &config.CredentialConfig{Value: accessKey},
SecretKey: &config.CredentialConfig{Value: secretAccessKey},
},
DisableSSL: true,
},
Mount: &config.MountConfig{
Path: []string{"/mount/"},
},
Actions: &config.ActionsConfig{
GET: &config.GetActionConfig{Enabled: true},
},
},
},
},
},
inputMethod: "GET",
inputURL: "http://localhost/mount/content-type/file.txt",
inputHeaders: map[string]string{
"Accept-Encoding": "gzip",
},
notExpectedBody: "test",
expectedCode: 200,
expectedHeaders: map[string]string{
"Cache-Control": "no-cache, no-store, no-transform, must-revalidate, private, max-age=0",
"Content-Type": "text/plain; charset=utf-8",
"Content-Encoding": "gzip",
},
},
{
name: "GET a file with success without compress enabled",
args: args{
cfg: &config.Config{
Server: &config.ServerConfig{
Compress: &config.ServerCompressConfig{
Enabled: &falseValue,
Level: config.DefaultServerCompressLevel,
Types: config.DefaultServerCompressTypes,
},
},
ListTargets: &config.ListTargetsConfig{},
Tracing: tracingConfig,
Templates: &config.TemplateConfig{
FolderList: "../../../templates/folder-list.tpl",
TargetList: "../../../templates/target-list.tpl",
NotFound: "../../../templates/not-found.tpl",
Forbidden: "../../../templates/forbidden.tpl",
BadRequest: "../../../templates/bad-request.tpl",
InternalServerError: "../../../templates/internal-server-error.tpl",
Unauthorized: "../../../templates/unauthorized.tpl",
},
Targets: []*config.TargetConfig{
{
Name: "target1",
Bucket: &config.BucketConfig{
Name: bucket,
Region: region,
S3Endpoint: s3server.URL,
Credentials: &config.BucketCredentialConfig{
AccessKey: &config.CredentialConfig{Value: accessKey},
SecretKey: &config.CredentialConfig{Value: secretAccessKey},
},
DisableSSL: true,
},
Mount: &config.MountConfig{
Path: []string{"/mount/"},
},
Actions: &config.ActionsConfig{
GET: &config.GetActionConfig{Enabled: true},
},
},
},
},
},
inputMethod: "GET",
inputURL: "http://localhost/mount/content-type/file.txt",
inputHeaders: map[string]string{
"Accept-Encoding": "gzip",
},
expectedBody: "test",
expectedCode: 200,
expectedHeaders: map[string]string{
"Cache-Control": "no-cache, no-store, no-transform, must-revalidate, private, max-age=0",
"Content-Type": "text/plain; charset=utf-8",
},
},
{
name: "GET a file with no cache enabled (no cache config)",
args: args{
Expand Down Expand Up @@ -2117,6 +2228,14 @@ func TestPublicRouter(t *testing.T) {
if tt.inputBasicUser != "" {
req.SetBasicAuth(tt.inputBasicUser, tt.inputBasicPassword)
}

// Add headers
if tt.inputHeaders != nil {
for key, value := range tt.inputHeaders {
req.Header.Set(key, value)
}
}

got.ServeHTTP(w, req)

if tt.expectedBody != "" {
Expand Down
13 changes: 13 additions & 0 deletions pkg/s3-proxy/server/utils_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,5 +76,18 @@ func setupFakeS3(accessKey, secretAccessKey, region, bucket string) (*httptest.S
}
}

// Add file with content-type
_, err = s3Client.PutObject(&s3.PutObjectInput{
Body: strings.NewReader("test"),
Bucket: aws.String(bucket),
Key: aws.String("content-type/file.txt"),
Metadata: map[string]*string{
"Content-Type": aws.String("text/plain"),
},
})
if err != nil {
return nil, err
}

return ts, nil
}

0 comments on commit 92387ac

Please # to comment.