Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'workhorse/internal/upload/destination/objectstore/test')
-rw-r--r--workhorse/internal/upload/destination/objectstore/test/gocloud_stub.go12
-rw-r--r--workhorse/internal/upload/destination/objectstore/test/objectstore_stub.go24
-rw-r--r--workhorse/internal/upload/destination/objectstore/test/s3_stub.go10
3 files changed, 23 insertions, 23 deletions
diff --git a/workhorse/internal/upload/destination/objectstore/test/gocloud_stub.go b/workhorse/internal/upload/destination/objectstore/test/gocloud_stub.go
index cf22075e407..bff0eabaee5 100644
--- a/workhorse/internal/upload/destination/objectstore/test/gocloud_stub.go
+++ b/workhorse/internal/upload/destination/objectstore/test/gocloud_stub.go
@@ -2,9 +2,7 @@ package test
import (
"context"
- "io/ioutil"
"net/url"
- "os"
"testing"
"github.com/stretchr/testify/require"
@@ -20,18 +18,14 @@ func (o *dirOpener) OpenBucketURL(ctx context.Context, u *url.URL) (*blob.Bucket
return fileblob.OpenBucket(o.tmpDir, nil)
}
-func SetupGoCloudFileBucket(t *testing.T, scheme string) (m *blob.URLMux, bucketDir string, cleanup func()) {
- tmpDir, err := ioutil.TempDir("", "")
- require.NoError(t, err)
+func SetupGoCloudFileBucket(t *testing.T, scheme string) (m *blob.URLMux, bucketDir string) {
+ tmpDir := t.TempDir()
mux := new(blob.URLMux)
fake := &dirOpener{tmpDir: tmpDir}
mux.RegisterBucket(scheme, fake)
- cleanup = func() {
- os.RemoveAll(tmpDir)
- }
- return mux, tmpDir, cleanup
+ return mux, tmpDir
}
func GoCloudObjectExists(t *testing.T, bucketDir string, objectName string) {
diff --git a/workhorse/internal/upload/destination/objectstore/test/objectstore_stub.go b/workhorse/internal/upload/destination/objectstore/test/objectstore_stub.go
index d51a2de7456..1a380bd5083 100644
--- a/workhorse/internal/upload/destination/objectstore/test/objectstore_stub.go
+++ b/workhorse/internal/upload/destination/objectstore/test/objectstore_stub.go
@@ -6,7 +6,6 @@ import (
"encoding/xml"
"fmt"
"io"
- "io/ioutil"
"net/http"
"net/http/httptest"
"strconv"
@@ -22,7 +21,8 @@ type partsEtagMap map[int]string
// Instead of storing objects it will just save md5sum.
type ObjectstoreStub struct {
// bucket contains md5sum of uploaded objects
- bucket map[string]string
+ bucket map[string]string
+ contents map[string][]byte
// overwriteMD5 contains overwrites for md5sum that should be return instead of the regular hash
overwriteMD5 map[string]string
// multipart is a map of MultipartUploads
@@ -48,6 +48,7 @@ func StartObjectStoreWithCustomMD5(md5Hashes map[string]string) (*ObjectstoreStu
multipart: make(map[string]partsEtagMap),
overwriteMD5: make(map[string]string),
headers: make(map[string]*http.Header),
+ contents: make(map[string][]byte),
}
for k, v := range md5Hashes {
@@ -82,6 +83,15 @@ func (o *ObjectstoreStub) GetObjectMD5(path string) string {
return o.bucket[path]
}
+// GetObject returns the contents of the uploaded object. The caller must
+// not modify the byte slice.
+func (o *ObjectstoreStub) GetObject(path string) []byte {
+ o.m.Lock()
+ defer o.m.Unlock()
+
+ return o.contents[path]
+}
+
// GetHeader returns a given HTTP header of the object uploaded to the path
func (o *ObjectstoreStub) GetHeader(path, key string) string {
o.m.Lock()
@@ -154,11 +164,11 @@ func (o *ObjectstoreStub) putObject(w http.ResponseWriter, r *http.Request) {
etag, overwritten := o.overwriteMD5[objectPath]
if !overwritten {
+ buf, _ := io.ReadAll(r.Body)
+ o.contents[objectPath] = buf
hasher := md5.New()
- io.Copy(hasher, r.Body)
-
- checksum := hasher.Sum(nil)
- etag = hex.EncodeToString(checksum)
+ hasher.Write(buf)
+ etag = hex.EncodeToString(hasher.Sum(nil))
}
o.headers[objectPath] = &r.Header
@@ -196,7 +206,7 @@ func (o *ObjectstoreStub) completeMultipartUpload(w http.ResponseWriter, r *http
return
}
- buf, err := ioutil.ReadAll(r.Body)
+ buf, err := io.ReadAll(r.Body)
if err != nil {
http.Error(w, err.Error(), 500)
return
diff --git a/workhorse/internal/upload/destination/objectstore/test/s3_stub.go b/workhorse/internal/upload/destination/objectstore/test/s3_stub.go
index 6b83426b852..6a6b4662904 100644
--- a/workhorse/internal/upload/destination/objectstore/test/s3_stub.go
+++ b/workhorse/internal/upload/destination/objectstore/test/s3_stub.go
@@ -1,7 +1,6 @@
package test
import (
- "io/ioutil"
"net/http/httptest"
"os"
"strings"
@@ -76,7 +75,7 @@ func S3ObjectExists(t *testing.T, sess *session.Session, config config.S3Config,
require.NoError(t, err)
require.Equal(t, int64(len(expectedBytes)), numBytes)
- output, err := ioutil.ReadFile(tmpfile.Name())
+ output, err := os.ReadFile(tmpfile.Name())
require.NoError(t, err)
require.Equal(t, []byte(expectedBytes), output)
@@ -124,13 +123,10 @@ func S3ObjectDoesNotExist(t *testing.T, sess *session.Session, config config.S3C
}
func downloadObject(t *testing.T, sess *session.Session, config config.S3Config, objectName string, handler func(tmpfile *os.File, numBytes int64, err error)) {
- tmpDir, err := ioutil.TempDir("", "workhorse-test-")
- require.NoError(t, err)
- defer os.Remove(tmpDir)
+ tmpDir := t.TempDir()
- tmpfile, err := ioutil.TempFile(tmpDir, "s3-output")
+ tmpfile, err := os.CreateTemp(tmpDir, "s3-output")
require.NoError(t, err)
- defer os.Remove(tmpfile.Name())
downloadSvc := s3manager.NewDownloader(sess)
numBytes, err := downloadSvc.Download(tmpfile, &s3.GetObjectInput{