Commit a9b8a122 authored by Jacob Vosmaer's avatar Jacob Vosmaer

Only use testify/require in object storage tests

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