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"
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"

View file

@ -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"

View file

@ -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).

View file

@ -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)

View file

@ -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)

View file

@ -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)

View file

@ -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)

View file

@ -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).