From bd11b4ce455f6744d3110590ff333babc0d0f78d Mon Sep 17 00:00:00 2001 From: Lena Fuhrimann <6780471+cloudlena@users.noreply.github.com> Date: Mon, 3 Apr 2017 22:19:07 +0200 Subject: [PATCH] Add happy test case --- bucket-view_test.go | 35 +++++++++++++++++++++++------------ 1 file changed, 23 insertions(+), 12 deletions(-) diff --git a/bucket-view_test.go b/bucket-view_test.go index 2d97bb7..084422e 100644 --- a/bucket-view_test.go +++ b/bucket-view_test.go @@ -9,6 +9,7 @@ import ( "testing" "github.com/gorilla/mux" + minio "github.com/minio/minio-go" "github.com/stretchr/testify/assert" ) @@ -16,24 +17,34 @@ func TestBucketViewHandler(t *testing.T) { assert := assert.New(t) tests := map[string]struct { - s3 S3Client - bucketName string - expectedStatusCode int - expectedBody string + s3 S3Client + bucketName string + expectedStatusCode int + expectedBodyCountains string }{ + "success": { + s3: &S3ClientMock{ + Buckets: []minio.BucketInfo{ + {Name: "testBucket"}, + }, + }, + bucketName: "testBucket", + expectedStatusCode: http.StatusOK, + expectedBodyCountains: "testBucket", + }, "bucket doesn't exist": { - s3: &S3ClientMock{}, - bucketName: "testBucket", - expectedStatusCode: http.StatusNotFound, - expectedBody: "bucket not found\n", + s3: &S3ClientMock{}, + bucketName: "testBucket", + expectedStatusCode: http.StatusNotFound, + expectedBodyCountains: "bucket not found\n", }, "s3 error": { s3: &S3ClientMock{ Err: errors.New("internal S3 error"), }, - bucketName: "testBucket", - expectedStatusCode: http.StatusInternalServerError, - expectedBody: "error listing objects\n", + bucketName: "testBucket", + expectedStatusCode: http.StatusInternalServerError, + expectedBodyCountains: "error listing objects\n", }, } @@ -56,6 +67,6 @@ func TestBucketViewHandler(t *testing.T) { assert.NoError(err) assert.Equal(tc.expectedStatusCode, resp.StatusCode) - assert.Equal(tc.expectedBody, string(body)) + assert.Contains(string(body), tc.expectedBodyCountains) } }