This commit is contained in:
Lena Fuhrimann 2017-04-18 15:43:13 +02:00
parent 6778d23090
commit 0c6ab519c6
2 changed files with 37 additions and 37 deletions

View file

@ -20,7 +20,7 @@ func TestBucketViewHandler(t *testing.T) {
s3 S3Client s3 S3Client
bucketName string bucketName string
expectedStatusCode int expectedStatusCode int
expectedBodyCountains string expectedBodyContains string
}{ }{
"success (empty bucket)": { "success (empty bucket)": {
s3: &S3ClientMock{ s3: &S3ClientMock{
@ -30,7 +30,7 @@ func TestBucketViewHandler(t *testing.T) {
}, },
bucketName: "testBucket", bucketName: "testBucket",
expectedStatusCode: http.StatusOK, expectedStatusCode: http.StatusOK,
expectedBodyCountains: "No objects in", expectedBodyContains: "No objects in",
}, },
"success (with file)": { "success (with file)": {
s3: &S3ClientMock{ s3: &S3ClientMock{
@ -43,7 +43,7 @@ func TestBucketViewHandler(t *testing.T) {
}, },
bucketName: "testBucket", bucketName: "testBucket",
expectedStatusCode: http.StatusOK, expectedStatusCode: http.StatusOK,
expectedBodyCountains: "testBucket", expectedBodyContains: "testBucket",
}, },
"success (archive)": { "success (archive)": {
s3: &S3ClientMock{ s3: &S3ClientMock{
@ -56,7 +56,7 @@ func TestBucketViewHandler(t *testing.T) {
}, },
bucketName: "testBucket", bucketName: "testBucket",
expectedStatusCode: http.StatusOK, expectedStatusCode: http.StatusOK,
expectedBodyCountains: "archive", expectedBodyContains: "archive",
}, },
"success (image)": { "success (image)": {
s3: &S3ClientMock{ s3: &S3ClientMock{
@ -69,7 +69,7 @@ func TestBucketViewHandler(t *testing.T) {
}, },
bucketName: "testBucket", bucketName: "testBucket",
expectedStatusCode: http.StatusOK, expectedStatusCode: http.StatusOK,
expectedBodyCountains: "photo", expectedBodyContains: "photo",
}, },
"success (sound)": { "success (sound)": {
s3: &S3ClientMock{ s3: &S3ClientMock{
@ -82,13 +82,13 @@ func TestBucketViewHandler(t *testing.T) {
}, },
bucketName: "testBucket", bucketName: "testBucket",
expectedStatusCode: http.StatusOK, expectedStatusCode: http.StatusOK,
expectedBodyCountains: "music_note", expectedBodyContains: "music_note",
}, },
"bucket doesn't exist": { "bucket doesn't exist": {
s3: &S3ClientMock{}, s3: &S3ClientMock{},
bucketName: "testBucket", bucketName: "testBucket",
expectedStatusCode: http.StatusNotFound, expectedStatusCode: http.StatusNotFound,
expectedBodyCountains: http.StatusText(http.StatusNotFound), expectedBodyContains: http.StatusText(http.StatusNotFound),
}, },
"s3 error": { "s3 error": {
s3: &S3ClientMock{ s3: &S3ClientMock{
@ -96,7 +96,7 @@ func TestBucketViewHandler(t *testing.T) {
}, },
bucketName: "testBucket", bucketName: "testBucket",
expectedStatusCode: http.StatusInternalServerError, expectedStatusCode: http.StatusInternalServerError,
expectedBodyCountains: http.StatusText(http.StatusInternalServerError), expectedBodyContains: http.StatusText(http.StatusInternalServerError),
}, },
} }
@ -119,6 +119,6 @@ func TestBucketViewHandler(t *testing.T) {
assert.NoError(err, tcID) assert.NoError(err, tcID)
assert.Equal(tc.expectedStatusCode, resp.StatusCode, tcID) assert.Equal(tc.expectedStatusCode, resp.StatusCode, tcID)
assert.Contains(string(body), tc.expectedBodyCountains, tcID) assert.Contains(string(body), tc.expectedBodyContains, tcID)
} }
} }

View file

@ -20,7 +20,7 @@ func TestGetObjectHandler(t *testing.T) {
bucketName string bucketName string
objectName string objectName string
expectedStatusCode int expectedStatusCode int
expectedBodyCountains string expectedBodyContains string
}{ }{
"s3 error": { "s3 error": {
s3: &S3ClientMock{ s3: &S3ClientMock{
@ -29,7 +29,7 @@ func TestGetObjectHandler(t *testing.T) {
bucketName: "testBucket", bucketName: "testBucket",
objectName: "testObject", objectName: "testObject",
expectedStatusCode: http.StatusInternalServerError, expectedStatusCode: http.StatusInternalServerError,
expectedBodyCountains: http.StatusText(http.StatusInternalServerError), expectedBodyContains: http.StatusText(http.StatusInternalServerError),
}, },
} }
@ -52,6 +52,6 @@ func TestGetObjectHandler(t *testing.T) {
assert.NoError(err, tcID) assert.NoError(err, tcID)
assert.Equal(tc.expectedStatusCode, resp.StatusCode, tcID) assert.Equal(tc.expectedStatusCode, resp.StatusCode, tcID)
assert.Contains(string(body), tc.expectedBodyCountains, tcID) assert.Contains(string(body), tc.expectedBodyContains, tcID)
} }
} }