Commit fdf60f09 authored by Alessio Caiazza's avatar Alessio Caiazza

Merge branch 'jv-remove-assert-object-storage' into 'master'

Only use testify/require in object storage tests NO CHANGELOG

See merge request gitlab-org/gitlab-workhorse!601
parents b50e0b70 a9b8a122
...@@ -14,7 +14,6 @@ import ( ...@@ -14,7 +14,6 @@ import (
"testing" "testing"
"time" "time"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
"gitlab.com/gitlab-org/gitlab-workhorse/internal/api" "gitlab.com/gitlab-org/gitlab-workhorse/internal/api"
...@@ -74,7 +73,7 @@ func TestUploadHandlerSendingToExternalStorage(t *testing.T) { ...@@ -74,7 +73,7 @@ func TestUploadHandlerSendingToExternalStorage(t *testing.T) {
storeServerCalled := 0 storeServerCalled := 0
storeServerMux := http.NewServeMux() storeServerMux := http.NewServeMux()
storeServerMux.HandleFunc("/url/put", func(w http.ResponseWriter, r *http.Request) { storeServerMux.HandleFunc("/url/put", func(w http.ResponseWriter, r *http.Request) {
assert.Equal(t, "PUT", r.Method) require.Equal(t, "PUT", r.Method)
receivedData, err := ioutil.ReadAll(r.Body) receivedData, err := ioutil.ReadAll(r.Body)
require.NoError(t, err) require.NoError(t, err)
...@@ -90,8 +89,8 @@ func TestUploadHandlerSendingToExternalStorage(t *testing.T) { ...@@ -90,8 +89,8 @@ func TestUploadHandlerSendingToExternalStorage(t *testing.T) {
responseProcessorCalled := 0 responseProcessorCalled := 0
responseProcessor := func(w http.ResponseWriter, r *http.Request) { responseProcessor := func(w http.ResponseWriter, r *http.Request) {
assert.Equal(t, "store-id", r.FormValue("file.remote_id")) require.Equal(t, "store-id", r.FormValue("file.remote_id"))
assert.NotEmpty(t, r.FormValue("file.remote_url")) require.NotEmpty(t, r.FormValue("file.remote_url"))
w.WriteHeader(200) w.WriteHeader(200)
responseProcessorCalled++ responseProcessorCalled++
} }
...@@ -127,8 +126,8 @@ func TestUploadHandlerSendingToExternalStorage(t *testing.T) { ...@@ -127,8 +126,8 @@ func TestUploadHandlerSendingToExternalStorage(t *testing.T) {
response := testUploadArtifacts(t, contentType, ts.URL+Path, &contentBuffer) response := testUploadArtifacts(t, contentType, ts.URL+Path, &contentBuffer)
require.Equal(t, http.StatusOK, response.Code) require.Equal(t, http.StatusOK, response.Code)
testhelper.RequireResponseHeader(t, response, MetadataHeaderKey, MetadataHeaderPresent) testhelper.RequireResponseHeader(t, response, MetadataHeaderKey, MetadataHeaderPresent)
assert.Equal(t, 1, storeServerCalled, "store should be called only once") require.Equal(t, 1, storeServerCalled, "store should be called only once")
assert.Equal(t, 1, responseProcessorCalled, "response processor should be called only once") require.Equal(t, 1, responseProcessorCalled, "response processor should be called only once")
}) })
} }
} }
...@@ -191,7 +190,7 @@ func TestUploadHandlerSendingToExternalStorageAndItReturnsAnError(t *testing.T) ...@@ -191,7 +190,7 @@ func TestUploadHandlerSendingToExternalStorageAndItReturnsAnError(t *testing.T)
storeServerMux := http.NewServeMux() storeServerMux := http.NewServeMux()
storeServerMux.HandleFunc("/url/put", func(w http.ResponseWriter, r *http.Request) { storeServerMux.HandleFunc("/url/put", func(w http.ResponseWriter, r *http.Request) {
putCalledTimes++ putCalledTimes++
assert.Equal(t, "PUT", r.Method) require.Equal(t, "PUT", r.Method)
w.WriteHeader(510) w.WriteHeader(510)
}) })
...@@ -214,7 +213,7 @@ func TestUploadHandlerSendingToExternalStorageAndItReturnsAnError(t *testing.T) ...@@ -214,7 +213,7 @@ func TestUploadHandlerSendingToExternalStorageAndItReturnsAnError(t *testing.T)
response := testUploadArtifactsFromTestZip(t, ts) response := testUploadArtifactsFromTestZip(t, ts)
require.Equal(t, http.StatusInternalServerError, response.Code) require.Equal(t, http.StatusInternalServerError, response.Code)
assert.Equal(t, 1, putCalledTimes, "upload should be called only once") require.Equal(t, 1, putCalledTimes, "upload should be called only once")
} }
func TestUploadHandlerSendingToExternalStorageAndSupportRequestTimeout(t *testing.T) { func TestUploadHandlerSendingToExternalStorageAndSupportRequestTimeout(t *testing.T) {
...@@ -223,7 +222,7 @@ func TestUploadHandlerSendingToExternalStorageAndSupportRequestTimeout(t *testin ...@@ -223,7 +222,7 @@ func TestUploadHandlerSendingToExternalStorageAndSupportRequestTimeout(t *testin
storeServerMux := http.NewServeMux() storeServerMux := http.NewServeMux()
storeServerMux.HandleFunc("/url/put", func(w http.ResponseWriter, r *http.Request) { storeServerMux.HandleFunc("/url/put", func(w http.ResponseWriter, r *http.Request) {
putCalledTimes++ putCalledTimes++
assert.Equal(t, "PUT", r.Method) require.Equal(t, "PUT", r.Method)
time.Sleep(10 * time.Second) time.Sleep(10 * time.Second)
w.WriteHeader(510) w.WriteHeader(510)
}) })
...@@ -248,7 +247,7 @@ func TestUploadHandlerSendingToExternalStorageAndSupportRequestTimeout(t *testin ...@@ -248,7 +247,7 @@ func TestUploadHandlerSendingToExternalStorageAndSupportRequestTimeout(t *testin
response := testUploadArtifactsFromTestZip(t, ts) response := testUploadArtifactsFromTestZip(t, ts)
require.Equal(t, http.StatusInternalServerError, response.Code) require.Equal(t, http.StatusInternalServerError, response.Code)
assert.Equal(t, 1, putCalledTimes, "upload should be called only once") require.Equal(t, 1, putCalledTimes, "upload should be called only once")
} }
func TestUploadHandlerMultipartUploadSizeLimit(t *testing.T) { func TestUploadHandlerMultipartUploadSizeLimit(t *testing.T) {
...@@ -288,8 +287,8 @@ func TestUploadHandlerMultipartUploadSizeLimit(t *testing.T) { ...@@ -288,8 +287,8 @@ func TestUploadHandlerMultipartUploadSizeLimit(t *testing.T) {
for i := 0; os.IsMultipartUpload(test.ObjectPath) && i < 100; i++ { for i := 0; os.IsMultipartUpload(test.ObjectPath) && i < 100; i++ {
time.Sleep(10 * time.Millisecond) time.Sleep(10 * time.Millisecond)
} }
assert.False(t, os.IsMultipartUpload(test.ObjectPath), "MultipartUpload should not be in progress anymore") require.False(t, os.IsMultipartUpload(test.ObjectPath), "MultipartUpload should not be in progress anymore")
assert.Empty(t, os.GetObjectMD5(test.ObjectPath), "upload should have failed, so the object should not exists") require.Empty(t, os.GetObjectMD5(test.ObjectPath), "upload should have failed, so the object should not exists")
} }
func TestUploadHandlerMultipartUploadMaximumSizeFromApi(t *testing.T) { func TestUploadHandlerMultipartUploadMaximumSizeFromApi(t *testing.T) {
......
...@@ -12,7 +12,6 @@ import ( ...@@ -12,7 +12,6 @@ import (
"time" "time"
"github.com/dgrijalva/jwt-go" "github.com/dgrijalva/jwt-go"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
"gocloud.dev/blob" "gocloud.dev/blob"
...@@ -26,7 +25,7 @@ func testDeadline() time.Time { ...@@ -26,7 +25,7 @@ func testDeadline() time.Time {
return time.Now().Add(filestore.DefaultObjectStoreTimeout) return time.Now().Add(filestore.DefaultObjectStoreTimeout)
} }
func assertFileGetsRemovedAsync(t *testing.T, filePath string) { func requireFileGetsRemovedAsync(t *testing.T, filePath string) {
var err error var err error
// Poll because the file removal is async // Poll because the file removal is async
...@@ -38,10 +37,10 @@ func assertFileGetsRemovedAsync(t *testing.T, filePath string) { ...@@ -38,10 +37,10 @@ func assertFileGetsRemovedAsync(t *testing.T, filePath string) {
time.Sleep(100 * time.Millisecond) time.Sleep(100 * time.Millisecond)
} }
assert.True(t, os.IsNotExist(err), "File hasn't been deleted during cleanup") require.True(t, os.IsNotExist(err), "File hasn't been deleted during cleanup")
} }
func assertObjectStoreDeletedAsync(t *testing.T, expectedDeletes int, osStub *test.ObjectstoreStub) { func requireObjectStoreDeletedAsync(t *testing.T, expectedDeletes int, osStub *test.ObjectstoreStub) {
// Poll because the object removal is async // Poll because the object removal is async
for i := 0; i < 100; i++ { for i := 0; i < 100; i++ {
if osStub.DeletesCnt() == expectedDeletes { if osStub.DeletesCnt() == expectedDeletes {
...@@ -50,7 +49,7 @@ func assertObjectStoreDeletedAsync(t *testing.T, expectedDeletes int, osStub *te ...@@ -50,7 +49,7 @@ func assertObjectStoreDeletedAsync(t *testing.T, expectedDeletes int, osStub *te
time.Sleep(10 * time.Millisecond) time.Sleep(10 * time.Millisecond)
} }
assert.Equal(t, expectedDeletes, osStub.DeletesCnt(), "Object not deleted") require.Equal(t, expectedDeletes, osStub.DeletesCnt(), "Object not deleted")
} }
func TestSaveFileWrongSize(t *testing.T) { func TestSaveFileWrongSize(t *testing.T) {
...@@ -63,10 +62,10 @@ func TestSaveFileWrongSize(t *testing.T) { ...@@ -63,10 +62,10 @@ func TestSaveFileWrongSize(t *testing.T) {
opts := &filestore.SaveFileOpts{LocalTempPath: tmpFolder, TempFilePrefix: "test-file"} opts := &filestore.SaveFileOpts{LocalTempPath: tmpFolder, TempFilePrefix: "test-file"}
fh, err := filestore.SaveFileFromReader(ctx, strings.NewReader(test.ObjectContent), test.ObjectSize+1, opts) fh, err := filestore.SaveFileFromReader(ctx, strings.NewReader(test.ObjectContent), test.ObjectSize+1, opts)
assert.Error(t, err) require.Error(t, err)
_, isSizeError := err.(filestore.SizeError) _, isSizeError := err.(filestore.SizeError)
assert.True(t, isSizeError, "Should fail with SizeError") require.True(t, isSizeError, "Should fail with SizeError")
assert.Nil(t, fh) require.Nil(t, fh)
} }
func TestSaveFileWithKnownSizeExceedLimit(t *testing.T) { func TestSaveFileWithKnownSizeExceedLimit(t *testing.T) {
...@@ -79,10 +78,10 @@ func TestSaveFileWithKnownSizeExceedLimit(t *testing.T) { ...@@ -79,10 +78,10 @@ func TestSaveFileWithKnownSizeExceedLimit(t *testing.T) {
opts := &filestore.SaveFileOpts{LocalTempPath: tmpFolder, TempFilePrefix: "test-file", MaximumSize: test.ObjectSize - 1} opts := &filestore.SaveFileOpts{LocalTempPath: tmpFolder, TempFilePrefix: "test-file", MaximumSize: test.ObjectSize - 1}
fh, err := filestore.SaveFileFromReader(ctx, strings.NewReader(test.ObjectContent), test.ObjectSize, opts) fh, err := filestore.SaveFileFromReader(ctx, strings.NewReader(test.ObjectContent), test.ObjectSize, opts)
assert.Error(t, err) require.Error(t, err)
_, isSizeError := err.(filestore.SizeError) _, isSizeError := err.(filestore.SizeError)
assert.True(t, isSizeError, "Should fail with SizeError") require.True(t, isSizeError, "Should fail with SizeError")
assert.Nil(t, fh) require.Nil(t, fh)
} }
func TestSaveFileWithUnknownSizeExceedLimit(t *testing.T) { func TestSaveFileWithUnknownSizeExceedLimit(t *testing.T) {
...@@ -95,17 +94,17 @@ func TestSaveFileWithUnknownSizeExceedLimit(t *testing.T) { ...@@ -95,17 +94,17 @@ func TestSaveFileWithUnknownSizeExceedLimit(t *testing.T) {
opts := &filestore.SaveFileOpts{LocalTempPath: tmpFolder, TempFilePrefix: "test-file", MaximumSize: test.ObjectSize - 1} opts := &filestore.SaveFileOpts{LocalTempPath: tmpFolder, TempFilePrefix: "test-file", MaximumSize: test.ObjectSize - 1}
fh, err := filestore.SaveFileFromReader(ctx, strings.NewReader(test.ObjectContent), -1, opts) fh, err := filestore.SaveFileFromReader(ctx, strings.NewReader(test.ObjectContent), -1, opts)
assert.Equal(t, err, filestore.ErrEntityTooLarge) require.Equal(t, err, filestore.ErrEntityTooLarge)
assert.Nil(t, fh) require.Nil(t, fh)
} }
func TestSaveFromDiskNotExistingFile(t *testing.T) { func TestSaveFromDiskNotExistingFile(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background()) ctx, cancel := context.WithCancel(context.Background())
defer cancel() defer cancel()
fh, err := filestore.SaveFileFromDisk(ctx, "/I/do/not/exist", &filestore.SaveFileOpts{}) fh, err := filestore.SaveFileFromDisk(ctx, "/I/do/not/exist", &filestore.SaveFileOpts{})
assert.Error(t, err, "SaveFileFromDisk should fail") require.Error(t, err, "SaveFileFromDisk should fail")
assert.True(t, os.IsNotExist(err), "Provided file should not exists") require.True(t, os.IsNotExist(err), "Provided file should not exists")
assert.Nil(t, fh, "On error FileHandler should be nil") require.Nil(t, fh, "On error FileHandler should be nil")
} }
func TestSaveFileWrongETag(t *testing.T) { func TestSaveFileWrongETag(t *testing.T) {
...@@ -141,13 +140,13 @@ func TestSaveFileWrongETag(t *testing.T) { ...@@ -141,13 +140,13 @@ func TestSaveFileWrongETag(t *testing.T) {
} }
ctx, cancel := context.WithCancel(context.Background()) ctx, cancel := context.WithCancel(context.Background())
fh, err := filestore.SaveFileFromReader(ctx, strings.NewReader(test.ObjectContent), test.ObjectSize, opts) fh, err := filestore.SaveFileFromReader(ctx, strings.NewReader(test.ObjectContent), test.ObjectSize, opts)
assert.Nil(t, fh) require.Nil(t, fh)
assert.Error(t, err) require.Error(t, err)
assert.Equal(t, 1, osStub.PutsCnt(), "File not uploaded") require.Equal(t, 1, osStub.PutsCnt(), "File not uploaded")
cancel() // this will trigger an async cleanup cancel() // this will trigger an async cleanup
assertObjectStoreDeletedAsync(t, 1, osStub) requireObjectStoreDeletedAsync(t, 1, osStub)
assert.False(t, spec.multipart && osStub.IsMultipartUpload(test.ObjectPath), "there must be no multipart upload in progress now") require.False(t, spec.multipart && osStub.IsMultipartUpload(test.ObjectPath), "there must be no multipart upload in progress now")
}) })
} }
} }
...@@ -169,12 +168,12 @@ func TestSaveFileFromDiskToLocalPath(t *testing.T) { ...@@ -169,12 +168,12 @@ func TestSaveFileFromDiskToLocalPath(t *testing.T) {
opts := &filestore.SaveFileOpts{LocalTempPath: tmpFolder} opts := &filestore.SaveFileOpts{LocalTempPath: tmpFolder}
fh, err := filestore.SaveFileFromDisk(ctx, f.Name(), opts) fh, err := filestore.SaveFileFromDisk(ctx, f.Name(), opts)
assert.NoError(t, err) require.NoError(t, err)
require.NotNil(t, fh) require.NotNil(t, fh)
assert.NotEmpty(t, fh.LocalPath, "File not persisted on disk") require.NotEmpty(t, fh.LocalPath, "File not persisted on disk")
_, err = os.Stat(fh.LocalPath) _, err = os.Stat(fh.LocalPath)
assert.NoError(t, err) require.NoError(t, err)
} }
func TestSaveFile(t *testing.T) { func TestSaveFile(t *testing.T) {
...@@ -246,24 +245,24 @@ func TestSaveFile(t *testing.T) { ...@@ -246,24 +245,24 @@ func TestSaveFile(t *testing.T) {
defer cancel() defer cancel()
fh, err := filestore.SaveFileFromReader(ctx, strings.NewReader(test.ObjectContent), test.ObjectSize, &opts) fh, err := filestore.SaveFileFromReader(ctx, strings.NewReader(test.ObjectContent), test.ObjectSize, &opts)
assert.NoError(t, err) require.NoError(t, err)
require.NotNil(t, fh) require.NotNil(t, fh)
require.Equal(t, opts.RemoteID, fh.RemoteID) require.Equal(t, opts.RemoteID, fh.RemoteID)
require.Equal(t, opts.RemoteURL, fh.RemoteURL) require.Equal(t, opts.RemoteURL, fh.RemoteURL)
if spec.local { if spec.local {
assert.NotEmpty(t, fh.LocalPath, "File not persisted on disk") require.NotEmpty(t, fh.LocalPath, "File not persisted on disk")
_, err := os.Stat(fh.LocalPath) _, err := os.Stat(fh.LocalPath)
assert.NoError(t, err) require.NoError(t, err)
dir := path.Dir(fh.LocalPath) dir := path.Dir(fh.LocalPath)
require.Equal(t, opts.LocalTempPath, dir) require.Equal(t, opts.LocalTempPath, dir)
filename := path.Base(fh.LocalPath) filename := path.Base(fh.LocalPath)
beginsWithPrefix := strings.HasPrefix(filename, opts.TempFilePrefix) beginsWithPrefix := strings.HasPrefix(filename, opts.TempFilePrefix)
assert.True(t, beginsWithPrefix, fmt.Sprintf("LocalPath filename %q do not begin with TempFilePrefix %q", filename, opts.TempFilePrefix)) require.True(t, beginsWithPrefix, fmt.Sprintf("LocalPath filename %q do not begin with TempFilePrefix %q", filename, opts.TempFilePrefix))
} else { } else {
assert.Empty(t, fh.LocalPath, "LocalPath must be empty for non local uploads") require.Empty(t, fh.LocalPath, "LocalPath must be empty for non local uploads")
} }
require.Equal(t, test.ObjectSize, fh.Size) require.Equal(t, test.ObjectSize, fh.Size)
...@@ -274,8 +273,8 @@ func TestSaveFile(t *testing.T) { ...@@ -274,8 +273,8 @@ func TestSaveFile(t *testing.T) {
require.Equal(t, 0, osStub.DeletesCnt(), "File deleted too early") require.Equal(t, 0, osStub.DeletesCnt(), "File deleted too early")
cancel() // this will trigger an async cleanup cancel() // this will trigger an async cleanup
assertObjectStoreDeletedAsync(t, expectedDeletes, osStub) requireObjectStoreDeletedAsync(t, expectedDeletes, osStub)
assertFileGetsRemovedAsync(t, fh.LocalPath) requireFileGetsRemovedAsync(t, fh.LocalPath)
// checking generated fields // checking generated fields
fields, err := fh.GitLabFinalizeFields("file") fields, err := fh.GitLabFinalizeFields("file")
...@@ -391,9 +390,9 @@ func TestSaveMultipartInBodyFailure(t *testing.T) { ...@@ -391,9 +390,9 @@ func TestSaveMultipartInBodyFailure(t *testing.T) {
defer cancel() defer cancel()
fh, err := filestore.SaveFileFromReader(ctx, strings.NewReader(test.ObjectContent), test.ObjectSize, &opts) fh, err := filestore.SaveFileFromReader(ctx, strings.NewReader(test.ObjectContent), test.ObjectSize, &opts)
assert.Nil(t, fh) require.Nil(t, fh)
require.Error(t, err) require.Error(t, err)
assert.EqualError(t, err, test.MultipartUploadInternalError().Error()) require.EqualError(t, err, test.MultipartUploadInternalError().Error())
} }
func checkFileHandlerWithFields(t *testing.T, fh *filestore.FileHandler, fields map[string]string, prefix string, remote bool) { func checkFileHandlerWithFields(t *testing.T, fh *filestore.FileHandler, fields map[string]string, prefix string, remote bool) {
......
...@@ -4,7 +4,6 @@ import ( ...@@ -4,7 +4,6 @@ import (
"testing" "testing"
"time" "time"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
"gitlab.com/gitlab-org/gitlab-workhorse/internal/api" "gitlab.com/gitlab-org/gitlab-workhorse/internal/api"
...@@ -50,8 +49,8 @@ func TestSaveFileOptsLocalAndRemote(t *testing.T) { ...@@ -50,8 +49,8 @@ func TestSaveFileOptsLocalAndRemote(t *testing.T) {
PartSize: test.partSize, PartSize: test.partSize,
} }
assert.Equal(t, test.isLocal, opts.IsLocal(), "IsLocal() mismatch") require.Equal(t, test.isLocal, opts.IsLocal(), "IsLocal() mismatch")
assert.Equal(t, test.isMultipart, opts.IsMultipart(), "IsMultipart() mismatch") require.Equal(t, test.isMultipart, opts.IsMultipart(), "IsMultipart() mismatch")
}) })
} }
} }
...@@ -109,30 +108,30 @@ func TestGetOpts(t *testing.T) { ...@@ -109,30 +108,30 @@ func TestGetOpts(t *testing.T) {
opts, err := filestore.GetOpts(apiResponse) opts, err := filestore.GetOpts(apiResponse)
require.NoError(t, err) require.NoError(t, err)
assert.Equal(t, apiResponse.TempPath, opts.LocalTempPath) require.Equal(t, apiResponse.TempPath, opts.LocalTempPath)
assert.WithinDuration(t, deadline, opts.Deadline, time.Second) require.WithinDuration(t, deadline, opts.Deadline, time.Second)
assert.Equal(t, apiResponse.RemoteObject.ID, opts.RemoteID) require.Equal(t, apiResponse.RemoteObject.ID, opts.RemoteID)
assert.Equal(t, apiResponse.RemoteObject.GetURL, opts.RemoteURL) require.Equal(t, apiResponse.RemoteObject.GetURL, opts.RemoteURL)
assert.Equal(t, apiResponse.RemoteObject.StoreURL, opts.PresignedPut) require.Equal(t, apiResponse.RemoteObject.StoreURL, opts.PresignedPut)
assert.Equal(t, apiResponse.RemoteObject.DeleteURL, opts.PresignedDelete) require.Equal(t, apiResponse.RemoteObject.DeleteURL, opts.PresignedDelete)
if test.customPutHeaders { if test.customPutHeaders {
assert.Equal(t, opts.PutHeaders, apiResponse.RemoteObject.PutHeaders) require.Equal(t, opts.PutHeaders, apiResponse.RemoteObject.PutHeaders)
} else { } else {
assert.Equal(t, opts.PutHeaders, map[string]string{"Content-Type": "application/octet-stream"}) require.Equal(t, opts.PutHeaders, map[string]string{"Content-Type": "application/octet-stream"})
} }
if test.multipart == nil { if test.multipart == nil {
assert.False(t, opts.IsMultipart()) require.False(t, opts.IsMultipart())
assert.Empty(t, opts.PresignedCompleteMultipart) require.Empty(t, opts.PresignedCompleteMultipart)
assert.Empty(t, opts.PresignedAbortMultipart) require.Empty(t, opts.PresignedAbortMultipart)
assert.Zero(t, opts.PartSize) require.Zero(t, opts.PartSize)
assert.Empty(t, opts.PresignedParts) require.Empty(t, opts.PresignedParts)
} else { } else {
assert.True(t, opts.IsMultipart()) require.True(t, opts.IsMultipart())
assert.Equal(t, test.multipart.CompleteURL, opts.PresignedCompleteMultipart) require.Equal(t, test.multipart.CompleteURL, opts.PresignedCompleteMultipart)
assert.Equal(t, test.multipart.AbortURL, opts.PresignedAbortMultipart) require.Equal(t, test.multipart.AbortURL, opts.PresignedAbortMultipart)
assert.Equal(t, test.multipart.PartSize, opts.PartSize) require.Equal(t, test.multipart.PartSize, opts.PartSize)
assert.Equal(t, test.multipart.PartURLs, opts.PresignedParts) require.Equal(t, test.multipart.PartURLs, opts.PresignedParts)
} }
}) })
} }
...@@ -166,7 +165,7 @@ func TestGetOptsDefaultTimeout(t *testing.T) { ...@@ -166,7 +165,7 @@ func TestGetOptsDefaultTimeout(t *testing.T) {
opts, err := filestore.GetOpts(&api.Response{TempPath: "/foo/bar"}) opts, err := filestore.GetOpts(&api.Response{TempPath: "/foo/bar"})
require.NoError(t, err) require.NoError(t, err)
assert.WithinDuration(t, deadline, opts.Deadline, time.Minute) require.WithinDuration(t, deadline, opts.Deadline, time.Minute)
} }
func TestUseWorkhorseClientEnabled(t *testing.T) { func TestUseWorkhorseClientEnabled(t *testing.T) {
......
...@@ -9,7 +9,6 @@ import ( ...@@ -9,7 +9,6 @@ import (
"testing" "testing"
"time" "time"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
"gitlab.com/gitlab-org/gitlab-workhorse/internal/objectstore" "gitlab.com/gitlab-org/gitlab-workhorse/internal/objectstore"
...@@ -41,21 +40,21 @@ func testObjectUploadNoErrors(t *testing.T, startObjectStore osFactory, useDelet ...@@ -41,21 +40,21 @@ func testObjectUploadNoErrors(t *testing.T, startObjectStore osFactory, useDelet
// copy data // copy data
n, err := io.Copy(object, strings.NewReader(test.ObjectContent)) n, err := io.Copy(object, strings.NewReader(test.ObjectContent))
assert.NoError(t, err) require.NoError(t, err)
assert.Equal(t, test.ObjectSize, n, "Uploaded file mismatch") require.Equal(t, test.ObjectSize, n, "Uploaded file mismatch")
// close HTTP stream // close HTTP stream
err = object.Close() err = object.Close()
assert.NoError(t, err) require.NoError(t, err)
assert.Equal(t, contentType, osStub.GetHeader(test.ObjectPath, "Content-Type")) require.Equal(t, contentType, osStub.GetHeader(test.ObjectPath, "Content-Type"))
// Checking MD5 extraction // Checking MD5 extraction
assert.Equal(t, osStub.GetObjectMD5(test.ObjectPath), object.ETag()) require.Equal(t, osStub.GetObjectMD5(test.ObjectPath), object.ETag())
// Checking cleanup // Checking cleanup
cancel() cancel()
assert.Equal(t, 1, osStub.PutsCnt(), "Object hasn't been uploaded") require.Equal(t, 1, osStub.PutsCnt(), "Object hasn't been uploaded")
var expectedDeleteCnt int var expectedDeleteCnt int
if useDeleteURL { if useDeleteURL {
...@@ -70,9 +69,9 @@ func testObjectUploadNoErrors(t *testing.T, startObjectStore osFactory, useDelet ...@@ -70,9 +69,9 @@ func testObjectUploadNoErrors(t *testing.T, startObjectStore osFactory, useDelet
} }
if useDeleteURL { if useDeleteURL {
assert.Equal(t, 1, osStub.DeletesCnt(), "Object hasn't been deleted") require.Equal(t, 1, osStub.DeletesCnt(), "Object hasn't been deleted")
} else { } else {
assert.Equal(t, 0, osStub.DeletesCnt(), "Object has been deleted") require.Equal(t, 0, osStub.DeletesCnt(), "Object has been deleted")
} }
} }
...@@ -112,9 +111,9 @@ func TestObjectUpload404(t *testing.T) { ...@@ -112,9 +111,9 @@ func TestObjectUpload404(t *testing.T) {
require.NoError(t, err) require.NoError(t, err)
_, err = io.Copy(object, strings.NewReader(test.ObjectContent)) _, err = io.Copy(object, strings.NewReader(test.ObjectContent))
assert.NoError(t, err) require.NoError(t, err)
err = object.Close() err = object.Close()
assert.Error(t, err) require.Error(t, err)
_, isStatusCodeError := err.(objectstore.StatusCodeError) _, isStatusCodeError := err.(objectstore.StatusCodeError)
require.True(t, isStatusCodeError, "Should fail with StatusCodeError") require.True(t, isStatusCodeError, "Should fail with StatusCodeError")
require.Contains(t, err.Error(), "404") require.Contains(t, err.Error(), "404")
......
...@@ -7,7 +7,6 @@ import ( ...@@ -7,7 +7,6 @@ import (
"strings" "strings"
"testing" "testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
) )
...@@ -29,21 +28,21 @@ func TestObjectStoreStub(t *testing.T) { ...@@ -29,21 +28,21 @@ func TestObjectStoreStub(t *testing.T) {
stub, ts := StartObjectStore() stub, ts := StartObjectStore()
defer ts.Close() defer ts.Close()
assert.Equal(t, 0, stub.PutsCnt()) require.Equal(t, 0, stub.PutsCnt())
assert.Equal(t, 0, stub.DeletesCnt()) require.Equal(t, 0, stub.DeletesCnt())
objectURL := ts.URL + ObjectPath objectURL := ts.URL + ObjectPath
require.NoError(t, doRequest(http.MethodPut, objectURL, strings.NewReader(ObjectContent))) require.NoError(t, doRequest(http.MethodPut, objectURL, strings.NewReader(ObjectContent)))
assert.Equal(t, 1, stub.PutsCnt()) require.Equal(t, 1, stub.PutsCnt())
assert.Equal(t, 0, stub.DeletesCnt()) require.Equal(t, 0, stub.DeletesCnt())
assert.Equal(t, ObjectMD5, stub.GetObjectMD5(ObjectPath)) require.Equal(t, ObjectMD5, stub.GetObjectMD5(ObjectPath))
require.NoError(t, doRequest(http.MethodDelete, objectURL, nil)) require.NoError(t, doRequest(http.MethodDelete, objectURL, nil))
assert.Equal(t, 1, stub.PutsCnt()) require.Equal(t, 1, stub.PutsCnt())
assert.Equal(t, 1, stub.DeletesCnt()) require.Equal(t, 1, stub.DeletesCnt())
} }
func TestObjectStoreStubDelete404(t *testing.T) { func TestObjectStoreStubDelete404(t *testing.T) {
...@@ -58,9 +57,9 @@ func TestObjectStoreStubDelete404(t *testing.T) { ...@@ -58,9 +57,9 @@ func TestObjectStoreStubDelete404(t *testing.T) {
resp, err := http.DefaultClient.Do(req) resp, err := http.DefaultClient.Do(req)
require.NoError(t, err) require.NoError(t, err)
defer resp.Body.Close() defer resp.Body.Close()
assert.Equal(t, 404, resp.StatusCode) require.Equal(t, 404, resp.StatusCode)
assert.Equal(t, 0, stub.DeletesCnt()) require.Equal(t, 0, stub.DeletesCnt())
} }
func TestObjectStoreInitiateMultipartUpload(t *testing.T) { func TestObjectStoreInitiateMultipartUpload(t *testing.T) {
...@@ -99,8 +98,8 @@ func TestObjectStoreCompleteMultipartUpload(t *testing.T) { ...@@ -99,8 +98,8 @@ func TestObjectStoreCompleteMultipartUpload(t *testing.T) {
stub.InitiateMultipartUpload(ObjectPath) stub.InitiateMultipartUpload(ObjectPath)
require.True(t, stub.IsMultipartUpload(ObjectPath)) require.True(t, stub.IsMultipartUpload(ObjectPath))
assert.Equal(t, 0, stub.PutsCnt()) require.Equal(t, 0, stub.PutsCnt())
assert.Equal(t, 0, stub.DeletesCnt()) require.Equal(t, 0, stub.DeletesCnt())
// Workhorse knows nothing about S3 MultipartUpload, it receives some URLs // Workhorse knows nothing about S3 MultipartUpload, it receives some URLs
// from GitLab-rails and PUTs chunk of data to each of them. // from GitLab-rails and PUTs chunk of data to each of them.
...@@ -116,11 +115,11 @@ func TestObjectStoreCompleteMultipartUpload(t *testing.T) { ...@@ -116,11 +115,11 @@ func TestObjectStoreCompleteMultipartUpload(t *testing.T) {
require.NoError(t, doRequest(http.MethodPut, partPutURL, strings.NewReader(part.content))) require.NoError(t, doRequest(http.MethodPut, partPutURL, strings.NewReader(part.content)))
assert.Equal(t, i+1, stub.PutsCnt()) require.Equal(t, i+1, stub.PutsCnt())
assert.Equal(t, 0, stub.DeletesCnt()) require.Equal(t, 0, stub.DeletesCnt())
assert.Equal(t, part.contentMD5, stub.multipart[ObjectPath][part.number], "Part %d was not uploaded into ObjectStorage", part.number) require.Equal(t, part.contentMD5, stub.multipart[ObjectPath][part.number], "Part %d was not uploaded into ObjectStorage", part.number)
assert.Empty(t, stub.GetObjectMD5(ObjectPath), "Part %d was mistakenly uploaded as a single object", part.number) require.Empty(t, stub.GetObjectMD5(ObjectPath), "Part %d was mistakenly uploaded as a single object", part.number)
assert.True(t, stub.IsMultipartUpload(ObjectPath), "MultipartUpload completed or aborted") require.True(t, stub.IsMultipartUpload(ObjectPath), "MultipartUpload completed or aborted")
} }
completeBody := fmt.Sprintf(`<CompleteMultipartUpload> completeBody := fmt.Sprintf(`<CompleteMultipartUpload>
...@@ -135,9 +134,9 @@ func TestObjectStoreCompleteMultipartUpload(t *testing.T) { ...@@ -135,9 +134,9 @@ func TestObjectStoreCompleteMultipartUpload(t *testing.T) {
</CompleteMultipartUpload>`, parts[0].contentMD5, parts[1].contentMD5) </CompleteMultipartUpload>`, parts[0].contentMD5, parts[1].contentMD5)
require.NoError(t, doRequest(http.MethodPost, completePostURL, strings.NewReader(completeBody))) require.NoError(t, doRequest(http.MethodPost, completePostURL, strings.NewReader(completeBody)))
assert.Equal(t, len(parts), stub.PutsCnt()) require.Equal(t, len(parts), stub.PutsCnt())
assert.Equal(t, 0, stub.DeletesCnt()) require.Equal(t, 0, stub.DeletesCnt())
assert.False(t, stub.IsMultipartUpload(ObjectPath), "MultipartUpload is still in progress") require.False(t, stub.IsMultipartUpload(ObjectPath), "MultipartUpload is still in progress")
} }
func TestObjectStoreAbortMultipartUpload(t *testing.T) { func TestObjectStoreAbortMultipartUpload(t *testing.T) {
...@@ -147,22 +146,22 @@ func TestObjectStoreAbortMultipartUpload(t *testing.T) { ...@@ -147,22 +146,22 @@ func TestObjectStoreAbortMultipartUpload(t *testing.T) {
stub.InitiateMultipartUpload(ObjectPath) stub.InitiateMultipartUpload(ObjectPath)
require.True(t, stub.IsMultipartUpload(ObjectPath)) require.True(t, stub.IsMultipartUpload(ObjectPath))
assert.Equal(t, 0, stub.PutsCnt()) require.Equal(t, 0, stub.PutsCnt())
assert.Equal(t, 0, stub.DeletesCnt()) require.Equal(t, 0, stub.DeletesCnt())
objectURL := ts.URL + ObjectPath objectURL := ts.URL + ObjectPath
require.NoError(t, doRequest(http.MethodPut, fmt.Sprintf("%s?partNumber=%d", objectURL, 1), strings.NewReader(ObjectContent))) require.NoError(t, doRequest(http.MethodPut, fmt.Sprintf("%s?partNumber=%d", objectURL, 1), strings.NewReader(ObjectContent)))
assert.Equal(t, 1, stub.PutsCnt()) require.Equal(t, 1, stub.PutsCnt())
assert.Equal(t, 0, stub.DeletesCnt()) require.Equal(t, 0, stub.DeletesCnt())
assert.Equal(t, ObjectMD5, stub.multipart[ObjectPath][1], "Part was not uploaded into ObjectStorage") require.Equal(t, ObjectMD5, stub.multipart[ObjectPath][1], "Part was not uploaded into ObjectStorage")
assert.Empty(t, stub.GetObjectMD5(ObjectPath), "Part was mistakenly uploaded as a single object") require.Empty(t, stub.GetObjectMD5(ObjectPath), "Part was mistakenly uploaded as a single object")
assert.True(t, stub.IsMultipartUpload(ObjectPath), "MultipartUpload completed or aborted") require.True(t, stub.IsMultipartUpload(ObjectPath), "MultipartUpload completed or aborted")
require.NoError(t, doRequest(http.MethodDelete, objectURL, nil)) require.NoError(t, doRequest(http.MethodDelete, objectURL, nil))
assert.Equal(t, 1, stub.PutsCnt()) require.Equal(t, 1, stub.PutsCnt())
assert.Equal(t, 1, stub.DeletesCnt()) require.Equal(t, 1, stub.DeletesCnt())
assert.Empty(t, stub.GetObjectMD5(ObjectPath), "MultiUpload has been completed") require.Empty(t, stub.GetObjectMD5(ObjectPath), "MultiUpload has been completed")
assert.False(t, stub.IsMultipartUpload(ObjectPath), "MultiUpload is still in progress") require.False(t, stub.IsMultipartUpload(ObjectPath), "MultiUpload is still in progress")
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment