Add happy test case

This commit is contained in:
Lena Fuhrimann 2017-04-03 22:19:07 +02:00
parent 3b08aca176
commit bd11b4ce45

View file

@ -9,6 +9,7 @@ import (
"testing" "testing"
"github.com/gorilla/mux" "github.com/gorilla/mux"
minio "github.com/minio/minio-go"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
) )
@ -16,24 +17,34 @@ func TestBucketViewHandler(t *testing.T) {
assert := assert.New(t) assert := assert.New(t)
tests := map[string]struct { tests := map[string]struct {
s3 S3Client s3 S3Client
bucketName string bucketName string
expectedStatusCode int expectedStatusCode int
expectedBody string expectedBodyCountains string
}{ }{
"success": {
s3: &S3ClientMock{
Buckets: []minio.BucketInfo{
{Name: "testBucket"},
},
},
bucketName: "testBucket",
expectedStatusCode: http.StatusOK,
expectedBodyCountains: "testBucket",
},
"bucket doesn't exist": { "bucket doesn't exist": {
s3: &S3ClientMock{}, s3: &S3ClientMock{},
bucketName: "testBucket", bucketName: "testBucket",
expectedStatusCode: http.StatusNotFound, expectedStatusCode: http.StatusNotFound,
expectedBody: "bucket not found\n", expectedBodyCountains: "bucket not found\n",
}, },
"s3 error": { "s3 error": {
s3: &S3ClientMock{ s3: &S3ClientMock{
Err: errors.New("internal S3 error"), Err: errors.New("internal S3 error"),
}, },
bucketName: "testBucket", bucketName: "testBucket",
expectedStatusCode: http.StatusInternalServerError, expectedStatusCode: http.StatusInternalServerError,
expectedBody: "error listing objects\n", expectedBodyCountains: "error listing objects\n",
}, },
} }
@ -56,6 +67,6 @@ func TestBucketViewHandler(t *testing.T) {
assert.NoError(err) assert.NoError(err)
assert.Equal(tc.expectedStatusCode, resp.StatusCode) assert.Equal(tc.expectedStatusCode, resp.StatusCode)
assert.Equal(tc.expectedBody, string(body)) assert.Contains(string(body), tc.expectedBodyCountains)
} }
} }