Improve test case descriptions

This commit is contained in:
Lena Fuhrimann 2017-12-21 07:50:59 +01:00
parent 22ab81b1ae
commit 0a0b2b440b
8 changed files with 52 additions and 52 deletions

22
Gopkg.lock generated
View file

@ -35,19 +35,19 @@
branch = "master" branch = "master"
name = "github.com/mastertinner/adapters" name = "github.com/mastertinner/adapters"
packages = [".","logging"] packages = [".","logging"]
revision = "c180cf74ef5c8cc76f0e2cf957c55375675e007f" revision = "f52f8e896fb9b6d7977f2feb502e18f0a061ba81"
[[projects]]
branch = "master"
name = "github.com/minio/go-homedir"
packages = ["."]
revision = "4d76aabb80b22bad8695d3904e943f1fb5e6199f"
[[projects]] [[projects]]
name = "github.com/minio/minio-go" name = "github.com/minio/minio-go"
packages = [".","pkg/credentials","pkg/encrypt","pkg/policy","pkg/s3signer","pkg/s3utils","pkg/set"] packages = [".","pkg/credentials","pkg/encrypt","pkg/policy","pkg/s3signer","pkg/s3utils","pkg/set"]
revision = "57a8ae886b49af6eb0d2c27c2d007ed2f71e1da5" revision = "06dcf064d9e3b1dfd21b9a01a822da7665a9c971"
version = "4.0.3" version = "4.0.4"
[[projects]]
branch = "master"
name = "github.com/mitchellh/go-homedir"
packages = ["."]
revision = "b8bc1bf767474819792c23f32d8286a45736f1c6"
[[projects]] [[projects]]
name = "github.com/pkg/errors" name = "github.com/pkg/errors"
@ -77,13 +77,13 @@
branch = "master" branch = "master"
name = "golang.org/x/crypto" name = "golang.org/x/crypto"
packages = ["ssh/terminal"] packages = ["ssh/terminal"]
revision = "94eea52f7b742c7cbe0b03b22f0c4c8631ece122" revision = "d585fd2cc9195196078f516b69daff6744ef5e84"
[[projects]] [[projects]]
branch = "master" branch = "master"
name = "golang.org/x/sys" name = "golang.org/x/sys"
packages = ["unix","windows"] packages = ["unix","windows"]
revision = "8b4580aae2a0dd0c231a45d3ccb8434ff533b840" revision = "d818ba11af4465e00c1998bd3f8a55603b422290"
[solve-meta] [solve-meta]
analyzer-name = "dep" analyzer-name = "dep"

View file

@ -31,7 +31,7 @@
[[constraint]] [[constraint]]
name = "github.com/minio/minio-go" name = "github.com/minio/minio-go"
version = "4.0.3" version = "4.0.4"
[[constraint]] [[constraint]]
name = "github.com/pkg/errors" name = "github.com/pkg/errors"

View file

@ -15,25 +15,13 @@ import (
) )
func TestBucketViewHandler(t *testing.T) { func TestBucketViewHandler(t *testing.T) {
assert := assert.New(t)
cases := map[string]struct { cases := map[string]struct {
s3 S3 s3 S3
bucketName string bucketName string
expectedStatusCode int expectedStatusCode int
expectedBodyContains string expectedBodyContains string
}{ }{
"success (empty bucket)": { "renders a bucket containing a file": {
s3: &s3Mock{
Buckets: []minio.BucketInfo{
{Name: "testBucket"},
},
},
bucketName: "testBucket",
expectedStatusCode: http.StatusOK,
expectedBodyContains: "No objects in",
},
"success (with file)": {
s3: &s3Mock{ s3: &s3Mock{
Buckets: []minio.BucketInfo{ Buckets: []minio.BucketInfo{
{Name: "testBucket"}, {Name: "testBucket"},
@ -46,7 +34,17 @@ func TestBucketViewHandler(t *testing.T) {
expectedStatusCode: http.StatusOK, expectedStatusCode: http.StatusOK,
expectedBodyContains: "testBucket", 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{ s3: &s3Mock{
Buckets: []minio.BucketInfo{ Buckets: []minio.BucketInfo{
{Name: "testBucket"}, {Name: "testBucket"},
@ -59,7 +57,7 @@ func TestBucketViewHandler(t *testing.T) {
expectedStatusCode: http.StatusOK, expectedStatusCode: http.StatusOK,
expectedBodyContains: "archive", expectedBodyContains: "archive",
}, },
"success (image)": { "renders a bucket containing an image": {
s3: &s3Mock{ s3: &s3Mock{
Buckets: []minio.BucketInfo{ Buckets: []minio.BucketInfo{
{Name: "testBucket"}, {Name: "testBucket"},
@ -72,7 +70,7 @@ func TestBucketViewHandler(t *testing.T) {
expectedStatusCode: http.StatusOK, expectedStatusCode: http.StatusOK,
expectedBodyContains: "photo", expectedBodyContains: "photo",
}, },
"success (sound)": { "renders a bucket containing a sound file": {
s3: &s3Mock{ s3: &s3Mock{
Buckets: []minio.BucketInfo{ Buckets: []minio.BucketInfo{
{Name: "testBucket"}, {Name: "testBucket"},
@ -85,13 +83,13 @@ func TestBucketViewHandler(t *testing.T) {
expectedStatusCode: http.StatusOK, expectedStatusCode: http.StatusOK,
expectedBodyContains: "music_note", expectedBodyContains: "music_note",
}, },
"bucket doesn't exist": { "returns error if the bucket doesn't exist": {
s3: &s3Mock{}, s3: &s3Mock{},
bucketName: "testBucket", bucketName: "testBucket",
expectedStatusCode: http.StatusNotFound, expectedStatusCode: http.StatusNotFound,
expectedBodyContains: http.StatusText(http.StatusNotFound), expectedBodyContains: http.StatusText(http.StatusNotFound),
}, },
"s3 error": { "returns error if there is an S3 error": {
s3: &s3Mock{ s3: &s3Mock{
Err: errors.New("mocked S3 error"), Err: errors.New("mocked S3 error"),
}, },
@ -103,6 +101,8 @@ func TestBucketViewHandler(t *testing.T) {
for tcID, tc := range cases { for tcID, tc := range cases {
t.Run(tcID, func(t *testing.T) { t.Run(tcID, func(t *testing.T) {
assert := assert.New(t)
r := mux.NewRouter() r := mux.NewRouter()
r. r.
Methods(http.MethodGet). Methods(http.MethodGet).

View file

@ -12,14 +12,12 @@ import (
) )
func TestBucketsViewHandler(t *testing.T) { func TestBucketsViewHandler(t *testing.T) {
assert := assert.New(t)
cases := map[string]struct { cases := map[string]struct {
s3 S3 s3 S3
expectedStatusCode int expectedStatusCode int
expectedBodyContains string expectedBodyContains string
}{ }{
"success": { "renders a list of buckets": {
s3: &s3Mock{ s3: &s3Mock{
Buckets: []minio.BucketInfo{ Buckets: []minio.BucketInfo{
{Name: "testBucket"}, {Name: "testBucket"},
@ -28,12 +26,12 @@ func TestBucketsViewHandler(t *testing.T) {
expectedStatusCode: http.StatusOK, expectedStatusCode: http.StatusOK,
expectedBodyContains: "testBucket", expectedBodyContains: "testBucket",
}, },
"success (bo buckets)": { "renders placeholder if no buckets": {
s3: &s3Mock{}, s3: &s3Mock{},
expectedStatusCode: http.StatusOK, expectedStatusCode: http.StatusOK,
expectedBodyContains: "No buckets yet", expectedBodyContains: "No buckets yet",
}, },
"s3 error": { "returns error if there is an S3 error": {
s3: &s3Mock{ s3: &s3Mock{
Err: errors.New("mocked S3 error"), Err: errors.New("mocked S3 error"),
}, },
@ -44,6 +42,8 @@ func TestBucketsViewHandler(t *testing.T) {
for tcID, tc := range cases { for tcID, tc := range cases {
t.Run(tcID, func(t *testing.T) { t.Run(tcID, func(t *testing.T) {
assert := assert.New(t)
req, err := http.NewRequest(http.MethodGet, "/buckets", nil) req, err := http.NewRequest(http.MethodGet, "/buckets", nil)
assert.NoError(err, tcID) assert.NoError(err, tcID)

View file

@ -12,33 +12,31 @@ import (
) )
func TestCreateBucketHandler(t *testing.T) { func TestCreateBucketHandler(t *testing.T) {
assert := assert.New(t)
cases := map[string]struct { cases := map[string]struct {
s3 S3 s3 S3
body string body string
expectedStatusCode int expectedStatusCode int
expectedBodyContains string expectedBodyContains string
}{ }{
"success": { "creates a new bucket": {
s3: &s3Mock{}, s3: &s3Mock{},
body: "{\"name\":\"myBucket\"}", body: "{\"name\":\"myBucket\"}",
expectedStatusCode: http.StatusCreated, expectedStatusCode: http.StatusCreated,
expectedBodyContains: "{\"name\":\"myBucket\",\"creationDate\":\"0001-01-01T00:00:00Z\"}\n", expectedBodyContains: "{\"name\":\"myBucket\",\"creationDate\":\"0001-01-01T00:00:00Z\"}\n",
}, },
"empty request": { "returns error for empty request": {
s3: &s3Mock{}, s3: &s3Mock{},
body: "", body: "",
expectedStatusCode: http.StatusUnprocessableEntity, expectedStatusCode: http.StatusUnprocessableEntity,
expectedBodyContains: http.StatusText(http.StatusUnprocessableEntity), expectedBodyContains: http.StatusText(http.StatusUnprocessableEntity),
}, },
"malformed request": { "returns error for malformed request": {
s3: &s3Mock{}, s3: &s3Mock{},
body: "}", body: "}",
expectedStatusCode: http.StatusUnprocessableEntity, expectedStatusCode: http.StatusUnprocessableEntity,
expectedBodyContains: http.StatusText(http.StatusUnprocessableEntity), expectedBodyContains: http.StatusText(http.StatusUnprocessableEntity),
}, },
"s3 error": { "returns error if there is an S3 error": {
s3: &s3Mock{ s3: &s3Mock{
Err: errors.New("mocked S3 error"), Err: errors.New("mocked S3 error"),
}, },
@ -50,6 +48,8 @@ func TestCreateBucketHandler(t *testing.T) {
for tcID, tc := range cases { for tcID, tc := range cases {
t.Run(tcID, func(t *testing.T) { t.Run(tcID, func(t *testing.T) {
assert := assert.New(t)
req, err := http.NewRequest(http.MethodPost, "/api/buckets", bytes.NewBufferString(tc.body)) req, err := http.NewRequest(http.MethodPost, "/api/buckets", bytes.NewBufferString(tc.body))
assert.NoError(err, tcID) assert.NoError(err, tcID)

View file

@ -11,19 +11,17 @@ import (
) )
func TestDeleteBucketHandler(t *testing.T) { func TestDeleteBucketHandler(t *testing.T) {
assert := assert.New(t)
cases := map[string]struct { cases := map[string]struct {
s3 S3 s3 S3
expectedStatusCode int expectedStatusCode int
expectedBodyContains string expectedBodyContains string
}{ }{
"success": { "deletes an existing bucket": {
s3: &s3Mock{}, s3: &s3Mock{},
expectedStatusCode: http.StatusNoContent, expectedStatusCode: http.StatusNoContent,
expectedBodyContains: "", expectedBodyContains: "",
}, },
"s3 error": { "returns error if there is an S3 error": {
s3: &s3Mock{ s3: &s3Mock{
Err: errors.New("mocked S3 error"), Err: errors.New("mocked S3 error"),
}, },
@ -34,6 +32,8 @@ func TestDeleteBucketHandler(t *testing.T) {
for tcID, tc := range cases { for tcID, tc := range cases {
t.Run(tcID, func(t *testing.T) { t.Run(tcID, func(t *testing.T) {
assert := assert.New(t)
req, err := http.NewRequest(http.MethodDelete, "/api/buckets/bucketName", nil) req, err := http.NewRequest(http.MethodDelete, "/api/buckets/bucketName", nil)
assert.NoError(err, tcID) assert.NoError(err, tcID)

View file

@ -11,19 +11,17 @@ import (
) )
func TestDeleteObjectHandler(t *testing.T) { func TestDeleteObjectHandler(t *testing.T) {
assert := assert.New(t)
cases := map[string]struct { cases := map[string]struct {
s3 S3 s3 S3
expectedStatusCode int expectedStatusCode int
expectedBodyContains string expectedBodyContains string
}{ }{
"success": { "deletes an existing object": {
s3: &s3Mock{}, s3: &s3Mock{},
expectedStatusCode: http.StatusNoContent, expectedStatusCode: http.StatusNoContent,
expectedBodyContains: "", expectedBodyContains: "",
}, },
"s3 error": { "returns error if there is an S3 error": {
s3: &s3Mock{ s3: &s3Mock{
Err: errors.New("mocked S3 error"), Err: errors.New("mocked S3 error"),
}, },
@ -34,6 +32,8 @@ func TestDeleteObjectHandler(t *testing.T) {
for tcID, tc := range cases { for tcID, tc := range cases {
t.Run(tcID, func(t *testing.T) { t.Run(tcID, func(t *testing.T) {
assert := assert.New(t)
req, err := http.NewRequest(http.MethodDelete, "/api/buckets/bucketName/objects/objectName", nil) req, err := http.NewRequest(http.MethodDelete, "/api/buckets/bucketName/objects/objectName", nil)
assert.NoError(err, tcID) assert.NoError(err, tcID)

View file

@ -14,8 +14,6 @@ import (
) )
func TestGetObjectHandler(t *testing.T) { func TestGetObjectHandler(t *testing.T) {
assert := assert.New(t)
cases := map[string]struct { cases := map[string]struct {
s3 S3 s3 S3
bucketName string bucketName string
@ -23,7 +21,7 @@ func TestGetObjectHandler(t *testing.T) {
expectedStatusCode int expectedStatusCode int
expectedBodyContains string expectedBodyContains string
}{ }{
"s3 error": { "returns error if there is an S3 error": {
s3: &s3Mock{ s3: &s3Mock{
Err: errors.New("mocked S3 error"), Err: errors.New("mocked S3 error"),
}, },
@ -36,6 +34,8 @@ func TestGetObjectHandler(t *testing.T) {
for tcID, tc := range cases { for tcID, tc := range cases {
t.Run(tcID, func(t *testing.T) { t.Run(tcID, func(t *testing.T) {
assert := assert.New(t)
r := mux.NewRouter() r := mux.NewRouter()
r. r.
Methods(http.MethodGet). Methods(http.MethodGet).