From 0a0b2b440bfbdf17df587f1657a955ce7a1f1546 Mon Sep 17 00:00:00 2001 From: Lena Fuhrimann <6780471+cloudlena@users.noreply.github.com> Date: Thu, 21 Dec 2017 07:50:59 +0100 Subject: [PATCH] Improve test case descriptions --- Gopkg.lock | 22 +++++++++++----------- Gopkg.toml | 2 +- bucket_view_test.go | 36 ++++++++++++++++++------------------ buckets_view_test.go | 10 +++++----- create_bucket_test.go | 12 ++++++------ delete_bucket_test.go | 8 ++++---- delete_object_test.go | 8 ++++---- get_object_test.go | 6 +++--- 8 files changed, 52 insertions(+), 52 deletions(-) diff --git a/Gopkg.lock b/Gopkg.lock index e6fa468..5244a2f 100644 --- a/Gopkg.lock +++ b/Gopkg.lock @@ -35,19 +35,19 @@ branch = "master" name = "github.com/mastertinner/adapters" packages = [".","logging"] - revision = "c180cf74ef5c8cc76f0e2cf957c55375675e007f" - -[[projects]] - branch = "master" - name = "github.com/minio/go-homedir" - packages = ["."] - revision = "4d76aabb80b22bad8695d3904e943f1fb5e6199f" + revision = "f52f8e896fb9b6d7977f2feb502e18f0a061ba81" [[projects]] name = "github.com/minio/minio-go" packages = [".","pkg/credentials","pkg/encrypt","pkg/policy","pkg/s3signer","pkg/s3utils","pkg/set"] - revision = "57a8ae886b49af6eb0d2c27c2d007ed2f71e1da5" - version = "4.0.3" + revision = "06dcf064d9e3b1dfd21b9a01a822da7665a9c971" + version = "4.0.4" + +[[projects]] + branch = "master" + name = "github.com/mitchellh/go-homedir" + packages = ["."] + revision = "b8bc1bf767474819792c23f32d8286a45736f1c6" [[projects]] name = "github.com/pkg/errors" @@ -77,13 +77,13 @@ branch = "master" name = "golang.org/x/crypto" packages = ["ssh/terminal"] - revision = "94eea52f7b742c7cbe0b03b22f0c4c8631ece122" + revision = "d585fd2cc9195196078f516b69daff6744ef5e84" [[projects]] branch = "master" name = "golang.org/x/sys" packages = ["unix","windows"] - revision = "8b4580aae2a0dd0c231a45d3ccb8434ff533b840" + revision = "d818ba11af4465e00c1998bd3f8a55603b422290" [solve-meta] analyzer-name = "dep" diff --git a/Gopkg.toml b/Gopkg.toml index 8e02153..094550f 100644 --- a/Gopkg.toml +++ b/Gopkg.toml @@ -31,7 +31,7 @@ [[constraint]] name = "github.com/minio/minio-go" - version = "4.0.3" + version = "4.0.4" [[constraint]] name = "github.com/pkg/errors" diff --git a/bucket_view_test.go b/bucket_view_test.go index b943b76..5e98f45 100644 --- a/bucket_view_test.go +++ b/bucket_view_test.go @@ -15,25 +15,13 @@ import ( ) func TestBucketViewHandler(t *testing.T) { - assert := assert.New(t) - cases := map[string]struct { s3 S3 bucketName string expectedStatusCode int expectedBodyContains string }{ - "success (empty bucket)": { - s3: &s3Mock{ - Buckets: []minio.BucketInfo{ - {Name: "testBucket"}, - }, - }, - bucketName: "testBucket", - expectedStatusCode: http.StatusOK, - expectedBodyContains: "No objects in", - }, - "success (with file)": { + "renders a bucket containing a file": { s3: &s3Mock{ Buckets: []minio.BucketInfo{ {Name: "testBucket"}, @@ -46,7 +34,17 @@ func TestBucketViewHandler(t *testing.T) { expectedStatusCode: http.StatusOK, expectedBodyContains: "testBucket", }, - "success (archive)": { + "renders placeholder for an empty bucket": { + s3: &s3Mock{ + Buckets: []minio.BucketInfo{ + {Name: "testBucket"}, + }, + }, + bucketName: "testBucket", + expectedStatusCode: http.StatusOK, + expectedBodyContains: "No objects in", + }, + "renders a bucket containing an archive": { s3: &s3Mock{ Buckets: []minio.BucketInfo{ {Name: "testBucket"}, @@ -59,7 +57,7 @@ func TestBucketViewHandler(t *testing.T) { expectedStatusCode: http.StatusOK, expectedBodyContains: "archive", }, - "success (image)": { + "renders a bucket containing an image": { s3: &s3Mock{ Buckets: []minio.BucketInfo{ {Name: "testBucket"}, @@ -72,7 +70,7 @@ func TestBucketViewHandler(t *testing.T) { expectedStatusCode: http.StatusOK, expectedBodyContains: "photo", }, - "success (sound)": { + "renders a bucket containing a sound file": { s3: &s3Mock{ Buckets: []minio.BucketInfo{ {Name: "testBucket"}, @@ -85,13 +83,13 @@ func TestBucketViewHandler(t *testing.T) { expectedStatusCode: http.StatusOK, expectedBodyContains: "music_note", }, - "bucket doesn't exist": { + "returns error if the bucket doesn't exist": { s3: &s3Mock{}, bucketName: "testBucket", expectedStatusCode: http.StatusNotFound, expectedBodyContains: http.StatusText(http.StatusNotFound), }, - "s3 error": { + "returns error if there is an S3 error": { s3: &s3Mock{ Err: errors.New("mocked S3 error"), }, @@ -103,6 +101,8 @@ func TestBucketViewHandler(t *testing.T) { for tcID, tc := range cases { t.Run(tcID, func(t *testing.T) { + assert := assert.New(t) + r := mux.NewRouter() r. Methods(http.MethodGet). diff --git a/buckets_view_test.go b/buckets_view_test.go index 777ea8a..d5c84d2 100644 --- a/buckets_view_test.go +++ b/buckets_view_test.go @@ -12,14 +12,12 @@ import ( ) func TestBucketsViewHandler(t *testing.T) { - assert := assert.New(t) - cases := map[string]struct { s3 S3 expectedStatusCode int expectedBodyContains string }{ - "success": { + "renders a list of buckets": { s3: &s3Mock{ Buckets: []minio.BucketInfo{ {Name: "testBucket"}, @@ -28,12 +26,12 @@ func TestBucketsViewHandler(t *testing.T) { expectedStatusCode: http.StatusOK, expectedBodyContains: "testBucket", }, - "success (bo buckets)": { + "renders placeholder if no buckets": { s3: &s3Mock{}, expectedStatusCode: http.StatusOK, expectedBodyContains: "No buckets yet", }, - "s3 error": { + "returns error if there is an S3 error": { s3: &s3Mock{ Err: errors.New("mocked S3 error"), }, @@ -44,6 +42,8 @@ func TestBucketsViewHandler(t *testing.T) { for tcID, tc := range cases { t.Run(tcID, func(t *testing.T) { + assert := assert.New(t) + req, err := http.NewRequest(http.MethodGet, "/buckets", nil) assert.NoError(err, tcID) diff --git a/create_bucket_test.go b/create_bucket_test.go index a87f3d8..b2309d3 100644 --- a/create_bucket_test.go +++ b/create_bucket_test.go @@ -12,33 +12,31 @@ import ( ) func TestCreateBucketHandler(t *testing.T) { - assert := assert.New(t) - cases := map[string]struct { s3 S3 body string expectedStatusCode int expectedBodyContains string }{ - "success": { + "creates a new bucket": { s3: &s3Mock{}, body: "{\"name\":\"myBucket\"}", expectedStatusCode: http.StatusCreated, expectedBodyContains: "{\"name\":\"myBucket\",\"creationDate\":\"0001-01-01T00:00:00Z\"}\n", }, - "empty request": { + "returns error for empty request": { s3: &s3Mock{}, body: "", expectedStatusCode: http.StatusUnprocessableEntity, expectedBodyContains: http.StatusText(http.StatusUnprocessableEntity), }, - "malformed request": { + "returns error for malformed request": { s3: &s3Mock{}, body: "}", expectedStatusCode: http.StatusUnprocessableEntity, expectedBodyContains: http.StatusText(http.StatusUnprocessableEntity), }, - "s3 error": { + "returns error if there is an S3 error": { s3: &s3Mock{ Err: errors.New("mocked S3 error"), }, @@ -50,6 +48,8 @@ func TestCreateBucketHandler(t *testing.T) { for tcID, tc := range cases { t.Run(tcID, func(t *testing.T) { + assert := assert.New(t) + req, err := http.NewRequest(http.MethodPost, "/api/buckets", bytes.NewBufferString(tc.body)) assert.NoError(err, tcID) diff --git a/delete_bucket_test.go b/delete_bucket_test.go index 54d9f97..6c27943 100644 --- a/delete_bucket_test.go +++ b/delete_bucket_test.go @@ -11,19 +11,17 @@ import ( ) func TestDeleteBucketHandler(t *testing.T) { - assert := assert.New(t) - cases := map[string]struct { s3 S3 expectedStatusCode int expectedBodyContains string }{ - "success": { + "deletes an existing bucket": { s3: &s3Mock{}, expectedStatusCode: http.StatusNoContent, expectedBodyContains: "", }, - "s3 error": { + "returns error if there is an S3 error": { s3: &s3Mock{ Err: errors.New("mocked S3 error"), }, @@ -34,6 +32,8 @@ func TestDeleteBucketHandler(t *testing.T) { for tcID, tc := range cases { t.Run(tcID, func(t *testing.T) { + assert := assert.New(t) + req, err := http.NewRequest(http.MethodDelete, "/api/buckets/bucketName", nil) assert.NoError(err, tcID) diff --git a/delete_object_test.go b/delete_object_test.go index 6f40804..3cded07 100644 --- a/delete_object_test.go +++ b/delete_object_test.go @@ -11,19 +11,17 @@ import ( ) func TestDeleteObjectHandler(t *testing.T) { - assert := assert.New(t) - cases := map[string]struct { s3 S3 expectedStatusCode int expectedBodyContains string }{ - "success": { + "deletes an existing object": { s3: &s3Mock{}, expectedStatusCode: http.StatusNoContent, expectedBodyContains: "", }, - "s3 error": { + "returns error if there is an S3 error": { s3: &s3Mock{ Err: errors.New("mocked S3 error"), }, @@ -34,6 +32,8 @@ func TestDeleteObjectHandler(t *testing.T) { for tcID, tc := range cases { t.Run(tcID, func(t *testing.T) { + assert := assert.New(t) + req, err := http.NewRequest(http.MethodDelete, "/api/buckets/bucketName/objects/objectName", nil) assert.NoError(err, tcID) diff --git a/get_object_test.go b/get_object_test.go index cb018e2..70e8d54 100644 --- a/get_object_test.go +++ b/get_object_test.go @@ -14,8 +14,6 @@ import ( ) func TestGetObjectHandler(t *testing.T) { - assert := assert.New(t) - cases := map[string]struct { s3 S3 bucketName string @@ -23,7 +21,7 @@ func TestGetObjectHandler(t *testing.T) { expectedStatusCode int expectedBodyContains string }{ - "s3 error": { + "returns error if there is an S3 error": { s3: &s3Mock{ Err: errors.New("mocked S3 error"), }, @@ -36,6 +34,8 @@ func TestGetObjectHandler(t *testing.T) { for tcID, tc := range cases { t.Run(tcID, func(t *testing.T) { + assert := assert.New(t) + r := mux.NewRouter() r. Methods(http.MethodGet).