diff --git a/Gopkg.lock b/Gopkg.lock index d449b7a..a8fa4ad 100644 --- a/Gopkg.lock +++ b/Gopkg.lock @@ -1,12 +1,6 @@ # This file is autogenerated, do not edit; changes may be undone by the next 'dep ensure'. -[[projects]] - name = "github.com/davecgh/go-spew" - packages = ["spew"] - revision = "346938d642f2ec3594ed81d874461961cd0faa76" - version = "v1.1.0" - [[projects]] branch = "master" name = "github.com/dustin/go-humanize" @@ -25,6 +19,12 @@ packages = ["logging"] revision = "368acae73d1569f0495b00991aaa85ec27d6ee8e" +[[projects]] + branch = "master" + name = "github.com/matryer/is" + packages = ["."] + revision = "be846f6cea707577c0d3a1e055d6cb719b68d533" + [[projects]] branch = "master" name = "github.com/matryer/way" @@ -56,24 +56,12 @@ revision = "645ef00459ed84a119197bfb8d8205042c6df63d" version = "v0.8.0" -[[projects]] - name = "github.com/pmezard/go-difflib" - packages = ["difflib"] - revision = "792786c7400a136282c1664665ae0a8db921c6c2" - version = "v1.0.0" - [[projects]] name = "github.com/sirupsen/logrus" packages = ["."] revision = "c155da19408a8799da419ed3eeb0cb5db0ad5dbc" version = "v1.0.5" -[[projects]] - name = "github.com/stretchr/testify" - packages = ["assert"] - revision = "12b6f73e6084dad08a7c6e575284b177ecafbc71" - version = "v1.2.1" - [[projects]] branch = "master" name = "golang.org/x/crypto" @@ -82,7 +70,7 @@ "blake2b", "ssh/terminal" ] - revision = "ab813273cd59e1333f7ae7bff5d027d4aadf528c" + revision = "5ba7f63082460102a45837dbd1827e10f9479ac0" [[projects]] branch = "master" @@ -127,6 +115,6 @@ [solve-meta] analyzer-name = "dep" analyzer-version = 1 - inputs-digest = "9f288d84be4931be1d2e9529f7e3350bbfaa9f6cb0968db278c6efddb54e9f64" + inputs-digest = "23fa3d7da0ea4b2f0e7ce3ea8744e41e550b3d7be5f0f0783e6ac0bb5b821508" solver-name = "gps-cdcl" solver-version = 1 diff --git a/Gopkg.toml b/Gopkg.toml index 5e2e70e..fb88a3e 100644 --- a/Gopkg.toml +++ b/Gopkg.toml @@ -29,6 +29,10 @@ branch = "master" name = "github.com/mastertinner/adapters" +[[constraint]] + branch = "master" + name = "github.com/matryer/is" + [[constraint]] branch = "master" name = "github.com/matryer/way" @@ -41,10 +45,6 @@ name = "github.com/pkg/errors" version = "0.8.0" -[[constraint]] - name = "github.com/stretchr/testify" - version = "1.2.1" - [prune] go-tests = true unused-packages = true diff --git a/internal/app/s3manager/bucket_view_test.go b/internal/app/s3manager/bucket_view_test.go index beb61c0..7a51713 100644 --- a/internal/app/s3manager/bucket_view_test.go +++ b/internal/app/s3manager/bucket_view_test.go @@ -7,12 +7,13 @@ import ( "net/http" "net/http/httptest" "path/filepath" + "strings" "testing" "github.com/mastertinner/s3manager/internal/app/s3manager" + "github.com/matryer/is" "github.com/matryer/way" minio "github.com/minio/minio-go" - "github.com/stretchr/testify/assert" ) func TestHandleBucketView(t *testing.T) { @@ -114,7 +115,7 @@ func TestHandleBucketView(t *testing.T) { for tcID, tc := range cases { t.Run(tcID, func(t *testing.T) { - assert := assert.New(t) + is := is.New(t) s3 := &S3Mock{ ListObjectsV2Func: tc.listObjectsV2Func, @@ -129,19 +130,14 @@ func TestHandleBucketView(t *testing.T) { url := fmt.Sprintf("%s/buckets/%s", ts.URL, tc.bucketName) resp, err := http.Get(url) - assert.NoError(err) - defer func() { - err = resp.Body.Close() - if err != nil { - t.FailNow() - } - }() + is.NoErr(err) + defer resp.Body.Close() body, err := ioutil.ReadAll(resp.Body) - assert.NoError(err) + is.NoErr(err) - assert.Equal(tc.expectedStatusCode, resp.StatusCode) - assert.Contains(string(body), tc.expectedBodyContains) + is.Equal(tc.expectedStatusCode, resp.StatusCode) // status code + is.True(strings.Contains(string(body), tc.expectedBodyContains)) // body }) } } diff --git a/internal/app/s3manager/buckets_view_test.go b/internal/app/s3manager/buckets_view_test.go index 5e3515b..df24427 100644 --- a/internal/app/s3manager/buckets_view_test.go +++ b/internal/app/s3manager/buckets_view_test.go @@ -5,11 +5,12 @@ import ( "net/http" "net/http/httptest" "path/filepath" + "strings" "testing" "github.com/mastertinner/s3manager/internal/app/s3manager" + "github.com/matryer/is" minio "github.com/minio/minio-go" - "github.com/stretchr/testify/assert" ) func TestHandleBucketsView(t *testing.T) { @@ -43,7 +44,7 @@ func TestHandleBucketsView(t *testing.T) { for tcID, tc := range cases { t.Run(tcID, func(t *testing.T) { - assert := assert.New(t) + is := is.New(t) s3 := &S3Mock{ ListBucketsFunc: tc.listBucketsFunc, @@ -52,7 +53,7 @@ func TestHandleBucketsView(t *testing.T) { tmplDir := filepath.Join("..", "..", "..", "web", "template") req, err := http.NewRequest(http.MethodGet, "/buckets", nil) - assert.NoError(err) + is.NoErr(err) rr := httptest.NewRecorder() handler := s3manager.HandleBucketsView(s3, tmplDir) @@ -60,8 +61,8 @@ func TestHandleBucketsView(t *testing.T) { handler.ServeHTTP(rr, req) resp := rr.Result() - assert.Equal(tc.expectedStatusCode, resp.StatusCode) - assert.Contains(rr.Body.String(), tc.expectedBodyContains) + is.Equal(tc.expectedStatusCode, resp.StatusCode) // status code + is.True(strings.Contains(rr.Body.String(), tc.expectedBodyContains)) // body }) } } diff --git a/internal/app/s3manager/create_bucket_test.go b/internal/app/s3manager/create_bucket_test.go index 62c52db..60d8e4a 100644 --- a/internal/app/s3manager/create_bucket_test.go +++ b/internal/app/s3manager/create_bucket_test.go @@ -5,10 +5,11 @@ import ( "errors" "net/http" "net/http/httptest" + "strings" "testing" "github.com/mastertinner/s3manager/internal/app/s3manager" - "github.com/stretchr/testify/assert" + "github.com/matryer/is" ) func TestHandleCreateBucket(t *testing.T) { @@ -54,14 +55,14 @@ func TestHandleCreateBucket(t *testing.T) { for tcID, tc := range cases { t.Run(tcID, func(t *testing.T) { - assert := assert.New(t) + is := is.New(t) s3 := &S3Mock{ MakeBucketFunc: tc.makeBucketFunc, } req, err := http.NewRequest(http.MethodPost, "/api/buckets", bytes.NewBufferString(tc.body)) - assert.NoError(err) + is.NoErr(err) rr := httptest.NewRecorder() handler := s3manager.HandleCreateBucket(s3) @@ -69,8 +70,8 @@ func TestHandleCreateBucket(t *testing.T) { handler.ServeHTTP(rr, req) resp := rr.Result() - assert.Equal(tc.expectedStatusCode, resp.StatusCode) - assert.Contains(rr.Body.String(), tc.expectedBodyContains) + is.Equal(tc.expectedStatusCode, resp.StatusCode) // status code + is.True(strings.Contains(rr.Body.String(), tc.expectedBodyContains)) // body }) } } diff --git a/internal/app/s3manager/create_object.go b/internal/app/s3manager/create_object.go index 341be22..a5eb045 100644 --- a/internal/app/s3manager/create_object.go +++ b/internal/app/s3manager/create_object.go @@ -1,7 +1,6 @@ package s3manager import ( - "log" "net/http" "github.com/matryer/way" @@ -24,12 +23,7 @@ func HandleCreateObject(s3 S3) http.HandlerFunc { handleHTTPError(w, errors.Wrap(err, "error getting file from form")) return } - defer func() { - err = file.Close() - if err != nil { - log.Fatalln(errors.Wrap(err, "error closing file")) - } - }() + defer file.Close() _, err = s3.PutObject(bucketName, handler.Filename, file, 1, minio.PutObjectOptions{ContentType: "application/octet-stream"}) if err != nil { diff --git a/internal/app/s3manager/delete_bucket_test.go b/internal/app/s3manager/delete_bucket_test.go index 8cf6b85..d0238d1 100644 --- a/internal/app/s3manager/delete_bucket_test.go +++ b/internal/app/s3manager/delete_bucket_test.go @@ -4,10 +4,11 @@ import ( "errors" "net/http" "net/http/httptest" + "strings" "testing" "github.com/mastertinner/s3manager/internal/app/s3manager" - "github.com/stretchr/testify/assert" + "github.com/matryer/is" ) func TestHandleDeleteBucket(t *testing.T) { @@ -34,14 +35,14 @@ func TestHandleDeleteBucket(t *testing.T) { for tcID, tc := range cases { t.Run(tcID, func(t *testing.T) { - assert := assert.New(t) + is := is.New(t) s3 := &S3Mock{ RemoveBucketFunc: tc.removeBucketFunc, } req, err := http.NewRequest(http.MethodDelete, "/api/buckets/bucketName", nil) - assert.NoError(err) + is.NoErr(err) rr := httptest.NewRecorder() handler := s3manager.HandleDeleteBucket(s3) @@ -49,8 +50,8 @@ func TestHandleDeleteBucket(t *testing.T) { handler.ServeHTTP(rr, req) resp := rr.Result() - assert.Equal(tc.expectedStatusCode, resp.StatusCode) - assert.Contains(rr.Body.String(), tc.expectedBodyContains) + is.Equal(tc.expectedStatusCode, resp.StatusCode) // status code + is.True(strings.Contains(rr.Body.String(), tc.expectedBodyContains)) // body }) } } diff --git a/internal/app/s3manager/delete_object_test.go b/internal/app/s3manager/delete_object_test.go index 275ac11..0a08a7a 100644 --- a/internal/app/s3manager/delete_object_test.go +++ b/internal/app/s3manager/delete_object_test.go @@ -4,10 +4,11 @@ import ( "errors" "net/http" "net/http/httptest" + "strings" "testing" "github.com/mastertinner/s3manager/internal/app/s3manager" - "github.com/stretchr/testify/assert" + "github.com/matryer/is" ) func TestHandleDeleteObject(t *testing.T) { @@ -34,22 +35,22 @@ func TestHandleDeleteObject(t *testing.T) { for tcID, tc := range cases { t.Run(tcID, func(t *testing.T) { - assert := assert.New(t) + is := is.New(t) s3 := &S3Mock{ RemoveObjectFunc: tc.removeObjectFunc, } req, err := http.NewRequest(http.MethodDelete, "/api/buckets/bucketName/objects/objectName", nil) - assert.NoError(err) + is.NoErr(err) rr := httptest.NewRecorder() handler := s3manager.HandleDeleteObject(s3) handler.ServeHTTP(rr, req) - assert.Equal(tc.expectedStatusCode, rr.Code) - assert.Contains(rr.Body.String(), tc.expectedBodyContains) + is.Equal(tc.expectedStatusCode, rr.Code) // status code + is.True(strings.Contains(rr.Body.String(), tc.expectedBodyContains)) // body }) } } diff --git a/internal/app/s3manager/get_object_test.go b/internal/app/s3manager/get_object_test.go index 81eafa1..423e2aa 100644 --- a/internal/app/s3manager/get_object_test.go +++ b/internal/app/s3manager/get_object_test.go @@ -6,12 +6,13 @@ import ( "io/ioutil" "net/http" "net/http/httptest" + "strings" "testing" "github.com/mastertinner/s3manager/internal/app/s3manager" + "github.com/matryer/is" "github.com/matryer/way" minio "github.com/minio/minio-go" - "github.com/stretchr/testify/assert" ) func TestHandleGetObject(t *testing.T) { @@ -35,7 +36,7 @@ func TestHandleGetObject(t *testing.T) { for tcID, tc := range cases { t.Run(tcID, func(t *testing.T) { - assert := assert.New(t) + is := is.New(t) s3 := &S3Mock{ GetObjectFunc: tc.getObjectFunc, @@ -49,19 +50,14 @@ func TestHandleGetObject(t *testing.T) { url := fmt.Sprintf("%s/buckets/%s/objects/%s", ts.URL, tc.bucketName, tc.objectName) resp, err := http.Get(url) - assert.NoError(err) - defer func() { - err = resp.Body.Close() - if err != nil { - t.FailNow() - } - }() + is.NoErr(err) + defer resp.Body.Close() body, err := ioutil.ReadAll(resp.Body) - assert.NoError(err) + is.NoErr(err) - assert.Equal(tc.expectedStatusCode, resp.StatusCode) - assert.Contains(string(body), tc.expectedBodyContains) + is.Equal(tc.expectedStatusCode, resp.StatusCode) // status code + is.True(strings.Contains(string(body), tc.expectedBodyContains)) // body }) } }