Skip to content

Commit

Permalink
Merge pull request #146 from harshavardhana/pr_out_refactor_tests_wit…
Browse files Browse the repository at this point in the history
…h_private_and_public

Refactor tests with private and public
  • Loading branch information
Harshavardhana committed Aug 9, 2015
2 parents 0befe11 + 07a4c4e commit d053903
Show file tree
Hide file tree
Showing 6 changed files with 152 additions and 124 deletions.
10 changes: 5 additions & 5 deletions api-multipart-v1.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ func (a apiV1) listMultipartUploads(bucket, keymarker, uploadIDMarker, prefix, d
}
if resp != nil {
if resp.StatusCode != http.StatusOK {
return listMultipartUploadsResult{}, a.ToErrorResponseBody(resp.Body)
return listMultipartUploadsResult{}, BodyToErrorResponse(resp.Body, a.config.AcceptType)
}
}
listMultipartUploadsResult := listMultipartUploadsResult{}
Expand Down Expand Up @@ -142,7 +142,7 @@ func (a apiV1) initiateMultipartUpload(bucket, object string) (initiateMultipart
}
if resp != nil {
if resp.StatusCode != http.StatusOK {
return initiateMultipartUploadResult{}, a.ToErrorResponseBody(resp.Body)
return initiateMultipartUploadResult{}, BodyToErrorResponse(resp.Body, a.config.AcceptType)
}
}
initiateMultipartUploadResult := initiateMultipartUploadResult{}
Expand Down Expand Up @@ -198,7 +198,7 @@ func (a apiV1) completeMultipartUpload(bucket, object, uploadID string, c comple
}
if resp != nil {
if resp.StatusCode != http.StatusOK {
return completeMultipartUploadResult{}, a.ToErrorResponseBody(resp.Body)
return completeMultipartUploadResult{}, BodyToErrorResponse(resp.Body, a.config.AcceptType)
}
}
completeMultipartUploadResult := completeMultipartUploadResult{}
Expand Down Expand Up @@ -308,7 +308,7 @@ func (a apiV1) listObjectParts(bucket, object, uploadID string, partNumberMarker
}
if resp != nil {
if resp.StatusCode != http.StatusOK {
return listObjectPartsResult{}, a.ToErrorResponseBody(resp.Body)
return listObjectPartsResult{}, BodyToErrorResponse(resp.Body, a.config.AcceptType)
}
}
listObjectPartsResult := listObjectPartsResult{}
Expand Down Expand Up @@ -358,7 +358,7 @@ func (a apiV1) uploadPart(bucket, object, uploadID string, md5SumBytes []byte, p
}
if resp != nil {
if resp.StatusCode != http.StatusOK {
return completePart{}, a.ToErrorResponseBody(resp.Body)
return completePart{}, BodyToErrorResponse(resp.Body, a.config.AcceptType)
}
}
return cPart, nil
Expand Down
16 changes: 8 additions & 8 deletions api-v1.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ func (a apiV1) putBucket(bucket, acl, location string) error {
}
if resp != nil {
if resp.StatusCode != http.StatusOK {
return a.ToErrorResponseBody(resp.Body)
return BodyToErrorResponse(resp.Body, a.config.AcceptType)
}
}
return nil
Expand Down Expand Up @@ -168,7 +168,7 @@ func (a apiV1) putBucketACL(bucket, acl string) error {
}
if resp != nil {
if resp.StatusCode != http.StatusOK {
return a.ToErrorResponseBody(resp.Body)
return BodyToErrorResponse(resp.Body, a.config.AcceptType)
}
}
return nil
Expand Down Expand Up @@ -201,7 +201,7 @@ func (a apiV1) getBucketACL(bucket string) (accessControlPolicy, error) {
}
if resp != nil {
if resp.StatusCode != http.StatusOK {
return accessControlPolicy{}, a.ToErrorResponseBody(resp.Body)
return accessControlPolicy{}, BodyToErrorResponse(resp.Body, a.config.AcceptType)
}
}
policy := accessControlPolicy{}
Expand Down Expand Up @@ -249,7 +249,7 @@ func (a apiV1) getBucketLocation(bucket string) (string, error) {
}
if resp != nil {
if resp.StatusCode != http.StatusOK {
return "", a.ToErrorResponseBody(resp.Body)
return "", BodyToErrorResponse(resp.Body, a.config.AcceptType)
}
}
var locationConstraint string
Expand Down Expand Up @@ -332,7 +332,7 @@ func (a apiV1) listObjects(bucket, marker, prefix, delimiter string, maxkeys int
}
if resp != nil {
if resp.StatusCode != http.StatusOK {
return listBucketResult{}, a.ToErrorResponseBody(resp.Body)
return listBucketResult{}, BodyToErrorResponse(resp.Body, a.config.AcceptType)
}
}
listBucketResult := listBucketResult{}
Expand Down Expand Up @@ -508,7 +508,7 @@ func (a apiV1) putObject(bucket, object, contentType string, md5SumBytes []byte,
}
if resp != nil {
if resp.StatusCode != http.StatusOK {
return ObjectStat{}, a.ToErrorResponseBody(resp.Body)
return ObjectStat{}, BodyToErrorResponse(resp.Body, a.config.AcceptType)
}
}
var metadata ObjectStat
Expand Down Expand Up @@ -609,7 +609,7 @@ func (a apiV1) getObject(bucket, object string, offset, length int64) (io.ReadCl
case http.StatusOK:
case http.StatusPartialContent:
default:
return nil, ObjectStat{}, a.ToErrorResponseBody(resp.Body)
return nil, ObjectStat{}, BodyToErrorResponse(resp.Body, a.config.AcceptType)
}
}
md5sum := strings.Trim(resp.Header.Get("ETag"), "\"") // trim off the odd double quotes
Expand Down Expand Up @@ -850,7 +850,7 @@ func (a apiV1) listBuckets() (listAllMyBucketsResult, error) {
}
}
if resp.StatusCode != http.StatusOK {
return listAllMyBucketsResult{}, a.ToErrorResponseBody(resp.Body)
return listAllMyBucketsResult{}, BodyToErrorResponse(resp.Body, a.config.AcceptType)
}
}
listAllMyBucketsResult := listAllMyBucketsResult{}
Expand Down
2 changes: 1 addition & 1 deletion api_handlers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

package minio
package minio_test

// bucketHandler is an http.Handler that verifies bucket responses and validates incoming requests
import (
Expand Down
116 changes: 116 additions & 0 deletions api_private_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
/*
* Minio Go Library for Amazon S3 compatible cloud storage (C) 2015 Minio, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package minio

import (
"strings"
"testing"
)

func TestACLTypes(t *testing.T) {
want := map[string]bool{
"private": true,
"public-read": true,
"public-read-write": true,
"authenticated-read": true,
"invalid": false,
}
for acl, ok := range want {
if BucketACL(acl).isValidBucketACL() != ok {
t.Fatal("Error")
}
}
}

func TestUserAgent(t *testing.T) {
conf := new(Config)
conf.SetUserAgent("minio", "1.0", "amd64")
if !strings.Contains(conf.userAgent, "minio") {
t.Fatalf("Error")
}
}

func TestGetRegion(t *testing.T) {
region, err := getRegion("s3.amazonaws.com")
if err != nil {
t.Fatalf("Error")
}
if region != "us-east-1" {
t.Fatalf("Error")
}
region, err = getRegion("localhost:9000")
if err != nil {
t.Fatalf("Error")
}
if region != "milkyway" {
t.Fatalf("Error")
}
}

func TestPartSize(t *testing.T) {
var maxPartSize int64 = 1024 * 1024 * 1024 * 5
partSize := getPartSize(5000000000000000000)
if partSize > minimumPartSize {
if partSize > maxPartSize {
t.Fatal("invalid result, cannot be bigger than maxPartSize 5GB")
}
}
partSize = getPartSize(50000000000)
if partSize > minimumPartSize {
t.Fatal("invalid result, cannot be bigger than minimumPartSize 5MB")
}
}

func TestURLEncoding(t *testing.T) {
type urlStrings struct {
name string
encodedName string
}

want := []urlStrings{
{
name: "bigfile-1._%",
encodedName: "bigfile-1._%25",
},
{
name: "本語",
encodedName: "%E6%9C%AC%E8%AA%9E",
},
{
name: "本語.1",
encodedName: "%E6%9C%AC%E8%AA%9E.1",
},
{
name: ">123>3123123",
encodedName: "%3E123%3E3123123",
},
{
name: "test 1 2.txt",
encodedName: "test%201%202.txt",
},
}

for _, u := range want {
encodedName, err := urlEncodeName(u.name)
if err != nil {
t.Fatalf("Error")
}
if u.encodedName != encodedName {
t.Errorf("Error")
}
}
}
Loading

0 comments on commit d053903

Please sign in to comment.