Make tests more BDD like

This commit is contained in:
Lena Fuhrimann 2019-01-08 08:51:09 +01:00
parent a45c259a41
commit a23628b1c9
8 changed files with 71 additions and 43 deletions

5
go.mod
View file

@ -9,10 +9,11 @@ require (
github.com/matryer/way v0.0.0-20180416093233-9632d0c407b0
github.com/minio/minio-go v6.0.11+incompatible
github.com/mitchellh/go-homedir v1.0.0 // indirect
github.com/pkg/errors v0.8.0
github.com/pkg/errors v0.8.1
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d // indirect
github.com/smartystreets/goconvey v0.0.0-20181108003508-044398e4856c // indirect
golang.org/x/crypto v0.0.0-20190103213133-ff983b9c42bc // indirect
golang.org/x/sys v0.0.0-20190102155601-82a175fd1598 // indirect
golang.org/x/net v0.0.0-20190107210223-45ffb0cd1ba0 // indirect
golang.org/x/sys v0.0.0-20190107173414-20be8e55dc7b // indirect
gopkg.in/ini.v1 v1.41.0 // indirect
)

10
go.sum
View file

@ -16,8 +16,8 @@ github.com/minio/minio-go v6.0.11+incompatible h1:ue0S9ZVNhy88iS+GM4y99k3oSSeKIF
github.com/minio/minio-go v6.0.11+incompatible/go.mod h1:7guKYtitv8dktvNUGrhzmNlA5wrAABTQXCoesZdFQO8=
github.com/mitchellh/go-homedir v1.0.0 h1:vKb8ShqSby24Yrqr/yDYkuFz8d0WUjys40rvnGC8aR0=
github.com/mitchellh/go-homedir v1.0.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
github.com/pkg/errors v0.8.0 h1:WdK/asTD0HN+q6hsWO3/vpuAkAr+tw6aNJNDFFf0+qw=
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I=
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d h1:zE9ykElWQ6/NYmHa3jpm/yHnI4xSofP+UP6SpjHcSeM=
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc=
github.com/smartystreets/goconvey v0.0.0-20181108003508-044398e4856c h1:Ho+uVpkel/udgjbwB5Lktg9BtvJSh2DT0Hi6LPSyI2w=
@ -27,10 +27,12 @@ golang.org/x/crypto v0.0.0-20190103213133-ff983b9c42bc/go.mod h1:6SG95UA2DQfeDnf
golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20181220203305-927f97764cc3 h1:eH6Eip3UpmR+yM/qI9Ijluzb1bNv/cAU/n+6l8tRSis=
golang.org/x/net v0.0.0-20181220203305-927f97764cc3/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20190107210223-45ffb0cd1ba0 h1:1DW40AJQ7AP4nY6ORUGUdkpXyEC9W2GAXcOPaMZK0K8=
golang.org/x/net v0.0.0-20190107210223-45ffb0cd1ba0/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/oauth2 v0.0.0-20181203162652-d668ce993890/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20190102155601-82a175fd1598 h1:S8GOgffXV1X3fpVG442QRfWOt0iFl79eHJ7OPt725bo=
golang.org/x/sys v0.0.0-20190102155601-82a175fd1598/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190107173414-20be8e55dc7b h1:9Gu1sMPgKHo+qCbPa2jN5A54ro2gY99BWF7nHOBNVME=
golang.org/x/sys v0.0.0-20190107173414-20be8e55dc7b/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=

View file

@ -18,13 +18,15 @@ import (
)
func TestHandleBucketView(t *testing.T) {
cases := map[string]struct {
cases := []struct {
it string
listObjectsV2Func func(string, string, bool, <-chan struct{}) <-chan minio.ObjectInfo
bucketName string
expectedStatusCode int
expectedBodyContains string
}{
"renders a bucket containing a file": {
{
it: "renders a bucket containing a file",
listObjectsV2Func: func(string, string, bool, <-chan struct{}) <-chan minio.ObjectInfo {
objCh := make(chan minio.ObjectInfo)
go func() {
@ -37,7 +39,8 @@ func TestHandleBucketView(t *testing.T) {
expectedStatusCode: http.StatusOK,
expectedBodyContains: "testFile",
},
"renders placeholder for an empty bucket": {
{
it: "renders placeholder for an empty bucket",
listObjectsV2Func: func(string, string, bool, <-chan struct{}) <-chan minio.ObjectInfo {
objCh := make(chan minio.ObjectInfo)
close(objCh)
@ -47,7 +50,8 @@ func TestHandleBucketView(t *testing.T) {
expectedStatusCode: http.StatusOK,
expectedBodyContains: "No objects in",
},
"renders a bucket containing an archive": {
{
it: "renders a bucket containing an archive",
listObjectsV2Func: func(string, string, bool, <-chan struct{}) <-chan minio.ObjectInfo {
objCh := make(chan minio.ObjectInfo)
go func() {
@ -60,7 +64,8 @@ func TestHandleBucketView(t *testing.T) {
expectedStatusCode: http.StatusOK,
expectedBodyContains: "archive",
},
"renders a bucket containing an image": {
{
it: "renders a bucket containing an image",
listObjectsV2Func: func(string, string, bool, <-chan struct{}) <-chan minio.ObjectInfo {
objCh := make(chan minio.ObjectInfo)
go func() {
@ -73,7 +78,8 @@ func TestHandleBucketView(t *testing.T) {
expectedStatusCode: http.StatusOK,
expectedBodyContains: "photo",
},
"renders a bucket containing a sound file": {
{
it: "renders a bucket containing a sound file",
listObjectsV2Func: func(string, string, bool, <-chan struct{}) <-chan minio.ObjectInfo {
objCh := make(chan minio.ObjectInfo)
go func() {
@ -86,7 +92,8 @@ func TestHandleBucketView(t *testing.T) {
expectedStatusCode: http.StatusOK,
expectedBodyContains: "music_note",
},
"returns error if the bucket doesn't exist": {
{
it: "returns error if the bucket doesn't exist",
listObjectsV2Func: func(string, string, bool, <-chan struct{}) <-chan minio.ObjectInfo {
objCh := make(chan minio.ObjectInfo)
go func() {
@ -99,7 +106,8 @@ func TestHandleBucketView(t *testing.T) {
expectedStatusCode: http.StatusNotFound,
expectedBodyContains: http.StatusText(http.StatusNotFound),
},
"returns error if there is an S3 error": {
{
it: "returns error if there is an S3 error",
listObjectsV2Func: func(string, string, bool, <-chan struct{}) <-chan minio.ObjectInfo {
objCh := make(chan minio.ObjectInfo)
go func() {
@ -114,8 +122,8 @@ func TestHandleBucketView(t *testing.T) {
},
}
for tcID, tc := range cases {
t.Run(tcID, func(t *testing.T) {
for _, tc := range cases {
t.Run(tc.it, func(t *testing.T) {
is := is.New(t)
s3 := &mocks.S3Mock{

View file

@ -16,26 +16,30 @@ import (
)
func TestHandleBucketsView(t *testing.T) {
cases := map[string]struct {
cases := []struct {
it string
listBucketsFunc func() ([]minio.BucketInfo, error)
expectedStatusCode int
expectedBodyContains string
}{
"renders a list of buckets": {
{
it: "renders a list of buckets",
listBucketsFunc: func() ([]minio.BucketInfo, error) {
return []minio.BucketInfo{{Name: "testBucket"}}, nil
},
expectedStatusCode: http.StatusOK,
expectedBodyContains: "testBucket",
},
"renders placeholder if no buckets": {
{
it: "renders placeholder if no buckets",
listBucketsFunc: func() ([]minio.BucketInfo, error) {
return []minio.BucketInfo{}, nil
},
expectedStatusCode: http.StatusOK,
expectedBodyContains: "No buckets yet",
},
"returns error if there is an S3 error": {
{
it: "returns error if there is an S3 error",
listBucketsFunc: func() ([]minio.BucketInfo, error) {
return []minio.BucketInfo{}, errors.New("mocked S3 error")
},
@ -44,8 +48,8 @@ func TestHandleBucketsView(t *testing.T) {
},
}
for tcID, tc := range cases {
t.Run(tcID, func(t *testing.T) {
for _, tc := range cases {
t.Run(tc.it, func(t *testing.T) {
is := is.New(t)
s3 := &mocks.S3Mock{

View file

@ -15,13 +15,15 @@ import (
)
func TestHandleCreateBucket(t *testing.T) {
cases := map[string]struct {
cases := []struct {
it string
makeBucketFunc func(string, string) error
body string
expectedStatusCode int
expectedBodyContains string
}{
"creates a new bucket": {
{
it: "creates a new bucket",
makeBucketFunc: func(string, string) error {
return nil
},
@ -29,7 +31,8 @@ func TestHandleCreateBucket(t *testing.T) {
expectedStatusCode: http.StatusCreated,
expectedBodyContains: `{"name":"myBucket","creationDate":"0001-01-01T00:00:00Z"}`,
},
"returns error for empty request": {
{
it: "returns error for empty request",
makeBucketFunc: func(string, string) error {
return nil
},
@ -37,7 +40,8 @@ func TestHandleCreateBucket(t *testing.T) {
expectedStatusCode: http.StatusUnprocessableEntity,
expectedBodyContains: http.StatusText(http.StatusUnprocessableEntity),
},
"returns error for malformed request": {
{
it: "returns error for malformed request",
makeBucketFunc: func(string, string) error {
return nil
},
@ -45,7 +49,8 @@ func TestHandleCreateBucket(t *testing.T) {
expectedStatusCode: http.StatusUnprocessableEntity,
expectedBodyContains: http.StatusText(http.StatusUnprocessableEntity),
},
"returns error if there is an S3 error": {
{
it: "returns error if there is an S3 error",
makeBucketFunc: func(string, string) error {
return errors.New("mocked S3 error")
},
@ -55,8 +60,8 @@ func TestHandleCreateBucket(t *testing.T) {
},
}
for tcID, tc := range cases {
t.Run(tcID, func(t *testing.T) {
for _, tc := range cases {
t.Run(tc.it, func(t *testing.T) {
is := is.New(t)
s3 := &mocks.S3Mock{

View file

@ -14,19 +14,22 @@ import (
)
func TestHandleDeleteBucket(t *testing.T) {
cases := map[string]struct {
cases := []struct {
it string
removeBucketFunc func(string) error
expectedStatusCode int
expectedBodyContains string
}{
"deletes an existing bucket": {
{
it: "deletes an existing bucket",
removeBucketFunc: func(string) error {
return nil
},
expectedStatusCode: http.StatusNoContent,
expectedBodyContains: "",
},
"returns error if there is an S3 error": {
{
it: "returns error if there is an S3 error",
removeBucketFunc: func(string) error {
return errors.New("mocked S3 error")
},
@ -35,8 +38,8 @@ func TestHandleDeleteBucket(t *testing.T) {
},
}
for tcID, tc := range cases {
t.Run(tcID, func(t *testing.T) {
for _, tc := range cases {
t.Run(tc.it, func(t *testing.T) {
is := is.New(t)
s3 := &mocks.S3Mock{

View file

@ -13,19 +13,22 @@ import (
)
func TestHandleDeleteObject(t *testing.T) {
cases := map[string]struct {
cases := []struct {
it string
removeObjectFunc func(string, string) error
expectedStatusCode int
expectedBodyContains string
}{
"deletes an existing object": {
{
it: "deletes an existing object",
removeObjectFunc: func(string, string) error {
return nil
},
expectedStatusCode: http.StatusNoContent,
expectedBodyContains: "",
},
"returns error if there is an S3 error": {
{
it: "returns error if there is an S3 error",
removeObjectFunc: func(string, string) error {
return errors.New("mocked S3 error")
},
@ -34,8 +37,8 @@ func TestHandleDeleteObject(t *testing.T) {
},
}
for tcID, tc := range cases {
t.Run(tcID, func(t *testing.T) {
for _, tc := range cases {
t.Run(tc.it, func(t *testing.T) {
is := is.New(t)
s3 := &mocks.S3Mock{

View file

@ -17,14 +17,16 @@ import (
)
func TestHandleGetObject(t *testing.T) {
cases := map[string]struct {
cases := []struct {
it string
getObjectFunc func(string, string, minio.GetObjectOptions) (*minio.Object, error)
bucketName string
objectName string
expectedStatusCode int
expectedBodyContains string
}{
"returns error if there is an S3 error": {
{
it: "returns error if there is an S3 error",
getObjectFunc: func(string, string, minio.GetObjectOptions) (*minio.Object, error) {
return nil, errors.New("mocked S3 error")
},
@ -35,8 +37,8 @@ func TestHandleGetObject(t *testing.T) {
},
}
for tcID, tc := range cases {
t.Run(tcID, func(t *testing.T) {
for _, tc := range cases {
t.Run(tc.it, func(t *testing.T) {
is := is.New(t)
s3 := &mocks.S3Mock{