From 5e8194e760008a2ec9762b4497e6b67dba00416f Mon Sep 17 00:00:00 2001 From: Lena Fuhrimann <6780471+cloudlena@users.noreply.github.com> Date: Mon, 4 May 2020 09:46:41 +0200 Subject: [PATCH] Fix linting issues --- internal/app/s3manager/bucket_view_test.go | 5 ++--- internal/app/s3manager/buckets_view_test.go | 3 +-- internal/app/s3manager/create_bucket_test.go | 3 +-- internal/app/s3manager/delete_bucket_test.go | 3 +-- internal/app/s3manager/delete_object_test.go | 3 +-- internal/app/s3manager/errors_test.go | 8 ++++++++ internal/app/s3manager/get_object_test.go | 3 +-- 7 files changed, 15 insertions(+), 13 deletions(-) create mode 100644 internal/app/s3manager/errors_test.go diff --git a/internal/app/s3manager/bucket_view_test.go b/internal/app/s3manager/bucket_view_test.go index 6286f7f..27cd3ec 100644 --- a/internal/app/s3manager/bucket_view_test.go +++ b/internal/app/s3manager/bucket_view_test.go @@ -1,7 +1,6 @@ package s3manager_test import ( - "errors" "fmt" "io/ioutil" "net/http" @@ -97,7 +96,7 @@ func TestHandleBucketView(t *testing.T) { listObjectsV2Func: func(string, string, bool, <-chan struct{}) <-chan minio.ObjectInfo { objCh := make(chan minio.ObjectInfo) go func() { - objCh <- minio.ObjectInfo{Err: errors.New("The specified bucket does not exist")} + objCh <- minio.ObjectInfo{Err: errBucketDoesNotExist} close(objCh) }() return objCh @@ -111,7 +110,7 @@ func TestHandleBucketView(t *testing.T) { listObjectsV2Func: func(string, string, bool, <-chan struct{}) <-chan minio.ObjectInfo { objCh := make(chan minio.ObjectInfo) go func() { - objCh <- minio.ObjectInfo{Err: errors.New("mocked S3 error")} + objCh <- minio.ObjectInfo{Err: errS3} close(objCh) }() return objCh diff --git a/internal/app/s3manager/buckets_view_test.go b/internal/app/s3manager/buckets_view_test.go index 8730175..ddf2967 100644 --- a/internal/app/s3manager/buckets_view_test.go +++ b/internal/app/s3manager/buckets_view_test.go @@ -1,7 +1,6 @@ package s3manager_test import ( - "errors" "io/ioutil" "net/http" "net/http/httptest" @@ -41,7 +40,7 @@ func TestHandleBucketsView(t *testing.T) { { it: "returns error if there is an S3 error", listBucketsFunc: func() ([]minio.BucketInfo, error) { - return []minio.BucketInfo{}, errors.New("mocked S3 error") + return []minio.BucketInfo{}, errS3 }, expectedStatusCode: http.StatusInternalServerError, expectedBodyContains: http.StatusText(http.StatusInternalServerError), diff --git a/internal/app/s3manager/create_bucket_test.go b/internal/app/s3manager/create_bucket_test.go index ee291e5..d0042ba 100644 --- a/internal/app/s3manager/create_bucket_test.go +++ b/internal/app/s3manager/create_bucket_test.go @@ -2,7 +2,6 @@ package s3manager_test import ( "bytes" - "errors" "io/ioutil" "net/http" "net/http/httptest" @@ -52,7 +51,7 @@ func TestHandleCreateBucket(t *testing.T) { { it: "returns error if there is an S3 error", makeBucketFunc: func(string, string) error { - return errors.New("mocked S3 error") + return errS3 }, body: `{"name":"myBucket"}`, expectedStatusCode: http.StatusInternalServerError, diff --git a/internal/app/s3manager/delete_bucket_test.go b/internal/app/s3manager/delete_bucket_test.go index 2f21fd0..9fd0425 100644 --- a/internal/app/s3manager/delete_bucket_test.go +++ b/internal/app/s3manager/delete_bucket_test.go @@ -1,7 +1,6 @@ package s3manager_test import ( - "errors" "io/ioutil" "net/http" "net/http/httptest" @@ -31,7 +30,7 @@ func TestHandleDeleteBucket(t *testing.T) { { it: "returns error if there is an S3 error", removeBucketFunc: func(string) error { - return errors.New("mocked S3 error") + return errS3 }, expectedStatusCode: http.StatusInternalServerError, expectedBodyContains: http.StatusText(http.StatusInternalServerError), diff --git a/internal/app/s3manager/delete_object_test.go b/internal/app/s3manager/delete_object_test.go index 6c63764..6ae3123 100644 --- a/internal/app/s3manager/delete_object_test.go +++ b/internal/app/s3manager/delete_object_test.go @@ -1,7 +1,6 @@ package s3manager_test import ( - "errors" "net/http" "net/http/httptest" "strings" @@ -30,7 +29,7 @@ func TestHandleDeleteObject(t *testing.T) { { it: "returns error if there is an S3 error", removeObjectFunc: func(string, string) error { - return errors.New("mocked S3 error") + return errS3 }, expectedStatusCode: http.StatusInternalServerError, expectedBodyContains: http.StatusText(http.StatusInternalServerError), diff --git a/internal/app/s3manager/errors_test.go b/internal/app/s3manager/errors_test.go new file mode 100644 index 0000000..68b06f6 --- /dev/null +++ b/internal/app/s3manager/errors_test.go @@ -0,0 +1,8 @@ +package s3manager_test + +import "errors" + +var ( + errS3 = errors.New("mocked s3 error") + errBucketDoesNotExist = errors.New("The specified bucket does not exist") // nolint: stylecheck +) diff --git a/internal/app/s3manager/get_object_test.go b/internal/app/s3manager/get_object_test.go index 3b9fb1b..53c3339 100644 --- a/internal/app/s3manager/get_object_test.go +++ b/internal/app/s3manager/get_object_test.go @@ -1,7 +1,6 @@ package s3manager_test import ( - "errors" "fmt" "io/ioutil" "net/http" @@ -28,7 +27,7 @@ func TestHandleGetObject(t *testing.T) { { 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") + return nil, errS3 }, bucketName: "testBucket", objectName: "testObject",