mirror of
https://github.com/distribution/distribution.git
synced 2025-09-15 06:39:25 +00:00
testing: replace legacy gopkg.in/check.v1
This commit replaces the legacy `gopkg.in/check.v1` testing dependency with `github.com/stretchr/testify`. Closes https://github.com/distribution/distribution/issues/3884. Signed-off-by: Eng Zer Jun <engzerjun@gmail.com>
This commit is contained in:
committed by
Milos Gajdos
parent
bdf70a1e46
commit
bcbf0431d1
@@ -10,7 +10,7 @@ import (
|
||||
|
||||
storagedriver "github.com/distribution/distribution/v3/registry/storage/driver"
|
||||
"github.com/distribution/distribution/v3/registry/storage/driver/testsuites"
|
||||
"gopkg.in/check.v1"
|
||||
"github.com/stretchr/testify/suite"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -24,9 +24,6 @@ const (
|
||||
var azureDriverConstructor func() (storagedriver.StorageDriver, error)
|
||||
var skipCheck func() string
|
||||
|
||||
// Hook up gocheck into the "go test" runner.
|
||||
func Test(t *testing.T) { check.TestingT(t) }
|
||||
|
||||
func init() {
|
||||
var (
|
||||
accountName string
|
||||
@@ -78,8 +75,33 @@ func init() {
|
||||
}
|
||||
return ""
|
||||
}
|
||||
}
|
||||
|
||||
testsuites.RegisterSuite(azureDriverConstructor, skipCheck)
|
||||
func newDriverSuite() *testsuites.DriverSuite {
|
||||
return testsuites.NewDriverSuite(azureDriverConstructor, skipCheck)
|
||||
}
|
||||
|
||||
func TestAzureDriverSuite(t *testing.T) {
|
||||
suite.Run(t, newDriverSuite())
|
||||
}
|
||||
|
||||
func BenchmarkAzureDriverSuite(b *testing.B) {
|
||||
benchsuite := testsuites.NewDriverBenchmarkSuite(newDriverSuite())
|
||||
benchsuite.Suite.SetupSuite()
|
||||
b.Cleanup(benchsuite.Suite.TearDownSuite)
|
||||
|
||||
b.Run("PutGetEmptyFiles", benchsuite.BenchmarkPutGetEmptyFiles)
|
||||
b.Run("PutGet1KBFiles", benchsuite.BenchmarkPutGet1KBFiles)
|
||||
b.Run("PutGet1MBFiles", benchsuite.BenchmarkPutGet1MBFiles)
|
||||
b.Run("PutGet1GBFiles", benchsuite.BenchmarkPutGet1GBFiles)
|
||||
b.Run("StreamEmptyFiles", benchsuite.BenchmarkStreamEmptyFiles)
|
||||
b.Run("Stream1KBFiles", benchsuite.BenchmarkStream1KBFiles)
|
||||
b.Run("Stream1MBFiles", benchsuite.BenchmarkStream1MBFiles)
|
||||
b.Run("Stream1GBFiles", benchsuite.BenchmarkStream1GBFiles)
|
||||
b.Run("List5Files", benchsuite.BenchmarkList5Files)
|
||||
b.Run("List50Files", benchsuite.BenchmarkList50Files)
|
||||
b.Run("Delete5Files", benchsuite.BenchmarkDelete5Files)
|
||||
b.Run("Delete50Files", benchsuite.BenchmarkDelete50Files)
|
||||
}
|
||||
|
||||
var letterRunes = []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")
|
||||
|
@@ -1,24 +1,16 @@
|
||||
package filesystem
|
||||
|
||||
import (
|
||||
"os"
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
storagedriver "github.com/distribution/distribution/v3/registry/storage/driver"
|
||||
"github.com/distribution/distribution/v3/registry/storage/driver/testsuites"
|
||||
"gopkg.in/check.v1"
|
||||
"github.com/stretchr/testify/suite"
|
||||
)
|
||||
|
||||
// Hook up gocheck into the "go test" runner.
|
||||
func Test(t *testing.T) { check.TestingT(t) }
|
||||
|
||||
func init() {
|
||||
root, err := os.MkdirTemp("", "driver-")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
defer os.Remove(root)
|
||||
func newDriverSuite(tb testing.TB) *testsuites.DriverSuite {
|
||||
root := tb.TempDir()
|
||||
|
||||
drvr, err := FromParameters(map[string]interface{}{
|
||||
"rootdirectory": root,
|
||||
@@ -27,11 +19,34 @@ func init() {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
testsuites.RegisterSuite(func() (storagedriver.StorageDriver, error) {
|
||||
return testsuites.NewDriverSuite(func() (storagedriver.StorageDriver, error) {
|
||||
return drvr, nil
|
||||
}, testsuites.NeverSkip)
|
||||
}
|
||||
|
||||
func TestFilesystemDriverSuite(t *testing.T) {
|
||||
suite.Run(t, newDriverSuite(t))
|
||||
}
|
||||
|
||||
func BenchmarkFilesystemDriverSuite(b *testing.B) {
|
||||
benchsuite := testsuites.NewDriverBenchmarkSuite(newDriverSuite(b))
|
||||
benchsuite.Suite.SetupSuite()
|
||||
b.Cleanup(benchsuite.Suite.TearDownSuite)
|
||||
|
||||
b.Run("PutGetEmptyFiles", benchsuite.BenchmarkPutGetEmptyFiles)
|
||||
b.Run("PutGet1KBFiles", benchsuite.BenchmarkPutGet1KBFiles)
|
||||
b.Run("PutGet1MBFiles", benchsuite.BenchmarkPutGet1MBFiles)
|
||||
b.Run("PutGet1GBFiles", benchsuite.BenchmarkPutGet1GBFiles)
|
||||
b.Run("StreamEmptyFiles", benchsuite.BenchmarkStreamEmptyFiles)
|
||||
b.Run("Stream1KBFiles", benchsuite.BenchmarkStream1KBFiles)
|
||||
b.Run("Stream1MBFiles", benchsuite.BenchmarkStream1MBFiles)
|
||||
b.Run("Stream1GBFiles", benchsuite.BenchmarkStream1GBFiles)
|
||||
b.Run("List5Files", benchsuite.BenchmarkList5Files)
|
||||
b.Run("List50Files", benchsuite.BenchmarkList50Files)
|
||||
b.Run("Delete5Files", benchsuite.BenchmarkDelete5Files)
|
||||
b.Run("Delete50Files", benchsuite.BenchmarkDelete50Files)
|
||||
}
|
||||
|
||||
func TestFromParametersImpl(t *testing.T) {
|
||||
tests := []struct {
|
||||
params map[string]interface{} // technically the yaml can contain anything
|
||||
|
@@ -10,16 +10,13 @@ import (
|
||||
"github.com/distribution/distribution/v3/internal/dcontext"
|
||||
storagedriver "github.com/distribution/distribution/v3/registry/storage/driver"
|
||||
"github.com/distribution/distribution/v3/registry/storage/driver/testsuites"
|
||||
"github.com/stretchr/testify/suite"
|
||||
"golang.org/x/oauth2"
|
||||
"golang.org/x/oauth2/google"
|
||||
"google.golang.org/api/googleapi"
|
||||
"google.golang.org/api/option"
|
||||
"gopkg.in/check.v1"
|
||||
)
|
||||
|
||||
// Hook up gocheck into the "go test" runner.
|
||||
func Test(t *testing.T) { check.TestingT(t) }
|
||||
|
||||
var (
|
||||
gcsDriverConstructor func(rootDirectory string) (storagedriver.StorageDriver, error)
|
||||
skipGCS func() string
|
||||
@@ -46,11 +43,6 @@ func init() {
|
||||
panic(fmt.Sprintf("Error reading JSON key : %v", err))
|
||||
}
|
||||
|
||||
root, err := os.MkdirTemp("", "driver-")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
defer os.Remove(root)
|
||||
var ts oauth2.TokenSource
|
||||
var email string
|
||||
var privateKey []byte
|
||||
@@ -82,7 +74,7 @@ func init() {
|
||||
gcsDriverConstructor = func(rootDirectory string) (storagedriver.StorageDriver, error) {
|
||||
parameters := driverParameters{
|
||||
bucket: bucket,
|
||||
rootDirectory: root,
|
||||
rootDirectory: rootDirectory,
|
||||
email: email,
|
||||
privateKey: privateKey,
|
||||
client: oauth2.NewClient(dcontext.Background(), ts),
|
||||
@@ -93,12 +85,39 @@ func init() {
|
||||
|
||||
return New(context.Background(), parameters)
|
||||
}
|
||||
}
|
||||
|
||||
testsuites.RegisterSuite(func() (storagedriver.StorageDriver, error) {
|
||||
func newDriverSuite(tb testing.TB) *testsuites.DriverSuite {
|
||||
root := tb.TempDir()
|
||||
|
||||
return testsuites.NewDriverSuite(func() (storagedriver.StorageDriver, error) {
|
||||
return gcsDriverConstructor(root)
|
||||
}, skipGCS)
|
||||
}
|
||||
|
||||
func TestGcsDriverSuite(t *testing.T) {
|
||||
suite.Run(t, newDriverSuite(t))
|
||||
}
|
||||
|
||||
func BenchmarkGcsDriverSuite(b *testing.B) {
|
||||
benchsuite := testsuites.NewDriverBenchmarkSuite(newDriverSuite(b))
|
||||
benchsuite.Suite.SetupSuite()
|
||||
b.Cleanup(benchsuite.Suite.TearDownSuite)
|
||||
|
||||
b.Run("PutGetEmptyFiles", benchsuite.BenchmarkPutGetEmptyFiles)
|
||||
b.Run("PutGet1KBFiles", benchsuite.BenchmarkPutGet1KBFiles)
|
||||
b.Run("PutGet1MBFiles", benchsuite.BenchmarkPutGet1MBFiles)
|
||||
b.Run("PutGet1GBFiles", benchsuite.BenchmarkPutGet1GBFiles)
|
||||
b.Run("StreamEmptyFiles", benchsuite.BenchmarkStreamEmptyFiles)
|
||||
b.Run("Stream1KBFiles", benchsuite.BenchmarkStream1KBFiles)
|
||||
b.Run("Stream1MBFiles", benchsuite.BenchmarkStream1MBFiles)
|
||||
b.Run("Stream1GBFiles", benchsuite.BenchmarkStream1GBFiles)
|
||||
b.Run("List5Files", benchsuite.BenchmarkList5Files)
|
||||
b.Run("List50Files", benchsuite.BenchmarkList50Files)
|
||||
b.Run("Delete5Files", benchsuite.BenchmarkDelete5Files)
|
||||
b.Run("Delete50Files", benchsuite.BenchmarkDelete50Files)
|
||||
}
|
||||
|
||||
// Test Committing a FileWriter without having called Write
|
||||
func TestCommitEmpty(t *testing.T) {
|
||||
if skipGCS() != "" {
|
||||
|
@@ -5,15 +5,35 @@ import (
|
||||
|
||||
storagedriver "github.com/distribution/distribution/v3/registry/storage/driver"
|
||||
"github.com/distribution/distribution/v3/registry/storage/driver/testsuites"
|
||||
"gopkg.in/check.v1"
|
||||
"github.com/stretchr/testify/suite"
|
||||
)
|
||||
|
||||
// Hook up gocheck into the "go test" runner.
|
||||
func Test(t *testing.T) { check.TestingT(t) }
|
||||
|
||||
func init() {
|
||||
func newDriverSuite() *testsuites.DriverSuite {
|
||||
inmemoryDriverConstructor := func() (storagedriver.StorageDriver, error) {
|
||||
return New(), nil
|
||||
}
|
||||
testsuites.RegisterSuite(inmemoryDriverConstructor, testsuites.NeverSkip)
|
||||
return testsuites.NewDriverSuite(inmemoryDriverConstructor, testsuites.NeverSkip)
|
||||
}
|
||||
|
||||
func TestInMemoryDriverSuite(t *testing.T) {
|
||||
suite.Run(t, newDriverSuite())
|
||||
}
|
||||
|
||||
func BenchmarkInMemoryDriverSuite(b *testing.B) {
|
||||
benchsuite := testsuites.NewDriverBenchmarkSuite(newDriverSuite())
|
||||
benchsuite.Suite.SetupSuite()
|
||||
b.Cleanup(benchsuite.Suite.TearDownSuite)
|
||||
|
||||
b.Run("PutGetEmptyFiles", benchsuite.BenchmarkPutGetEmptyFiles)
|
||||
b.Run("PutGet1KBFiles", benchsuite.BenchmarkPutGet1KBFiles)
|
||||
b.Run("PutGet1MBFiles", benchsuite.BenchmarkPutGet1MBFiles)
|
||||
b.Run("PutGet1GBFiles", benchsuite.BenchmarkPutGet1GBFiles)
|
||||
b.Run("StreamEmptyFiles", benchsuite.BenchmarkStreamEmptyFiles)
|
||||
b.Run("Stream1KBFiles", benchsuite.BenchmarkStream1KBFiles)
|
||||
b.Run("Stream1MBFiles", benchsuite.BenchmarkStream1MBFiles)
|
||||
b.Run("Stream1GBFiles", benchsuite.BenchmarkStream1GBFiles)
|
||||
b.Run("List5Files", benchsuite.BenchmarkList5Files)
|
||||
b.Run("List50Files", benchsuite.BenchmarkList50Files)
|
||||
b.Run("Delete5Files", benchsuite.BenchmarkDelete5Files)
|
||||
b.Run("Delete50Files", benchsuite.BenchmarkDelete50Files)
|
||||
}
|
||||
|
@@ -4,20 +4,14 @@ import (
|
||||
"context"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"gopkg.in/check.v1"
|
||||
)
|
||||
|
||||
func Test(t *testing.T) { check.TestingT(t) }
|
||||
|
||||
type MiddlewareSuite struct{}
|
||||
|
||||
var _ = check.Suite(&MiddlewareSuite{})
|
||||
|
||||
func (s *MiddlewareSuite) TestNoConfig(c *check.C) {
|
||||
func TestNoConfig(t *testing.T) {
|
||||
options := make(map[string]interface{})
|
||||
_, err := newCloudFrontStorageMiddleware(context.Background(), nil, options)
|
||||
c.Assert(err, check.ErrorMatches, "no baseurl provided")
|
||||
if err == nil || err.Error() != "no baseurl provided" {
|
||||
t.Fatalf(`expected error "no baseurl provided", got: %v`, err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCloudFrontStorageMiddlewareGenerateKey(t *testing.T) {
|
||||
|
@@ -4,99 +4,93 @@ import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"gopkg.in/check.v1"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func Test(t *testing.T) { check.TestingT(t) }
|
||||
|
||||
type MiddlewareSuite struct{}
|
||||
|
||||
var _ = check.Suite(&MiddlewareSuite{})
|
||||
|
||||
func (s *MiddlewareSuite) TestNoConfig(c *check.C) {
|
||||
func TestNoConfig(t *testing.T) {
|
||||
options := make(map[string]interface{})
|
||||
_, err := newRedirectStorageMiddleware(context.Background(), nil, options)
|
||||
c.Assert(err, check.ErrorMatches, "no baseurl provided")
|
||||
require.ErrorContains(t, err, "no baseurl provided")
|
||||
}
|
||||
|
||||
func (s *MiddlewareSuite) TestMissingScheme(c *check.C) {
|
||||
func TestMissingScheme(t *testing.T) {
|
||||
options := make(map[string]interface{})
|
||||
options["baseurl"] = "example.com"
|
||||
_, err := newRedirectStorageMiddleware(context.Background(), nil, options)
|
||||
c.Assert(err, check.ErrorMatches, "no scheme specified for redirect baseurl")
|
||||
require.ErrorContains(t, err, "no scheme specified for redirect baseurl")
|
||||
}
|
||||
|
||||
func (s *MiddlewareSuite) TestHttpsPort(c *check.C) {
|
||||
func TestHttpsPort(t *testing.T) {
|
||||
options := make(map[string]interface{})
|
||||
options["baseurl"] = "https://example.com:5443"
|
||||
middleware, err := newRedirectStorageMiddleware(context.Background(), nil, options)
|
||||
c.Assert(err, check.Equals, nil)
|
||||
require.NoError(t, err)
|
||||
|
||||
m, ok := middleware.(*redirectStorageMiddleware)
|
||||
c.Assert(ok, check.Equals, true)
|
||||
c.Assert(m.scheme, check.Equals, "https")
|
||||
c.Assert(m.host, check.Equals, "example.com:5443")
|
||||
require.True(t, ok)
|
||||
require.Equal(t, "https", m.scheme)
|
||||
require.Equal(t, "example.com:5443", m.host)
|
||||
|
||||
url, err := middleware.RedirectURL(nil, "/rick/data")
|
||||
c.Assert(err, check.Equals, nil)
|
||||
c.Assert(url, check.Equals, "https://example.com:5443/rick/data")
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, "https://example.com:5443/rick/data", url)
|
||||
}
|
||||
|
||||
func (s *MiddlewareSuite) TestHTTP(c *check.C) {
|
||||
func TestHTTP(t *testing.T) {
|
||||
options := make(map[string]interface{})
|
||||
options["baseurl"] = "http://example.com"
|
||||
middleware, err := newRedirectStorageMiddleware(context.Background(), nil, options)
|
||||
c.Assert(err, check.Equals, nil)
|
||||
require.NoError(t, err)
|
||||
|
||||
m, ok := middleware.(*redirectStorageMiddleware)
|
||||
c.Assert(ok, check.Equals, true)
|
||||
c.Assert(m.scheme, check.Equals, "http")
|
||||
c.Assert(m.host, check.Equals, "example.com")
|
||||
require.True(t, ok)
|
||||
require.Equal(t, "http", m.scheme)
|
||||
require.Equal(t, "example.com", m.host)
|
||||
|
||||
url, err := middleware.RedirectURL(nil, "morty/data")
|
||||
c.Assert(err, check.Equals, nil)
|
||||
c.Assert(url, check.Equals, "http://example.com/morty/data")
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, "http://example.com/morty/data", url)
|
||||
}
|
||||
|
||||
func (s *MiddlewareSuite) TestPath(c *check.C) {
|
||||
func TestPath(t *testing.T) {
|
||||
// basePath: end with no slash
|
||||
options := make(map[string]interface{})
|
||||
options["baseurl"] = "https://example.com/path"
|
||||
middleware, err := newRedirectStorageMiddleware(context.Background(), nil, options)
|
||||
c.Assert(err, check.Equals, nil)
|
||||
require.NoError(t, err)
|
||||
|
||||
m, ok := middleware.(*redirectStorageMiddleware)
|
||||
c.Assert(ok, check.Equals, true)
|
||||
c.Assert(m.scheme, check.Equals, "https")
|
||||
c.Assert(m.host, check.Equals, "example.com")
|
||||
c.Assert(m.basePath, check.Equals, "/path")
|
||||
require.True(t, ok)
|
||||
require.Equal(t, "https", m.scheme)
|
||||
require.Equal(t, "example.com", m.host)
|
||||
require.Equal(t, "/path", m.basePath)
|
||||
|
||||
// call RedirectURL() with no leading slash
|
||||
url, err := middleware.RedirectURL(nil, "morty/data")
|
||||
c.Assert(err, check.Equals, nil)
|
||||
c.Assert(url, check.Equals, "https://example.com/path/morty/data")
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, "https://example.com/path/morty/data", url)
|
||||
// call RedirectURL() with leading slash
|
||||
url, err = middleware.RedirectURL(nil, "/morty/data")
|
||||
c.Assert(err, check.Equals, nil)
|
||||
c.Assert(url, check.Equals, "https://example.com/path/morty/data")
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, "https://example.com/path/morty/data", url)
|
||||
|
||||
// basePath: end with slash
|
||||
options["baseurl"] = "https://example.com/path/"
|
||||
middleware, err = newRedirectStorageMiddleware(context.Background(), nil, options)
|
||||
c.Assert(err, check.Equals, nil)
|
||||
require.NoError(t, err)
|
||||
|
||||
m, ok = middleware.(*redirectStorageMiddleware)
|
||||
c.Assert(ok, check.Equals, true)
|
||||
c.Assert(m.scheme, check.Equals, "https")
|
||||
c.Assert(m.host, check.Equals, "example.com")
|
||||
c.Assert(m.basePath, check.Equals, "/path/")
|
||||
require.True(t, ok)
|
||||
require.Equal(t, "https", m.scheme)
|
||||
require.Equal(t, "example.com", m.host)
|
||||
require.Equal(t, "/path/", m.basePath)
|
||||
|
||||
// call RedirectURL() with no leading slash
|
||||
url, err = middleware.RedirectURL(nil, "morty/data")
|
||||
c.Assert(err, check.Equals, nil)
|
||||
c.Assert(url, check.Equals, "https://example.com/path/morty/data")
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, "https://example.com/path/morty/data", url)
|
||||
// call RedirectURL() with leading slash
|
||||
url, err = middleware.RedirectURL(nil, "/morty/data")
|
||||
c.Assert(err, check.Equals, nil)
|
||||
c.Assert(url, check.Equals, "https://example.com/path/morty/data")
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, "https://example.com/path/morty/data", url)
|
||||
}
|
||||
|
@@ -16,6 +16,7 @@ import (
|
||||
|
||||
"github.com/aws/aws-sdk-go/aws"
|
||||
"github.com/aws/aws-sdk-go/service/s3"
|
||||
"github.com/stretchr/testify/suite"
|
||||
|
||||
"github.com/distribution/distribution/v3/internal/dcontext"
|
||||
storagedriver "github.com/distribution/distribution/v3/registry/storage/driver"
|
||||
@@ -48,12 +49,7 @@ func init() {
|
||||
logLevel = os.Getenv("S3_LOGLEVEL")
|
||||
)
|
||||
|
||||
root, err := os.MkdirTemp("", "driver-")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
defer os.Remove(root)
|
||||
|
||||
var err error
|
||||
s3DriverConstructor = func(rootDirectory, storageClass string) (*Driver, error) {
|
||||
encryptBool := false
|
||||
if encrypt != "" {
|
||||
@@ -152,12 +148,39 @@ func init() {
|
||||
}
|
||||
return ""
|
||||
}
|
||||
}
|
||||
|
||||
testsuites.RegisterSuite(func() (storagedriver.StorageDriver, error) {
|
||||
func newDriverSuite(tb testing.TB) *testsuites.DriverSuite {
|
||||
root := tb.TempDir()
|
||||
|
||||
return testsuites.NewDriverSuite(func() (storagedriver.StorageDriver, error) {
|
||||
return s3DriverConstructor(root, s3.StorageClassStandard)
|
||||
}, skipS3)
|
||||
}
|
||||
|
||||
func TestS3DriverSuite(t *testing.T) {
|
||||
suite.Run(t, newDriverSuite(t))
|
||||
}
|
||||
|
||||
func BenchmarkS3DriverSuite(b *testing.B) {
|
||||
benchsuite := testsuites.NewDriverBenchmarkSuite(newDriverSuite(b))
|
||||
benchsuite.Suite.SetupSuite()
|
||||
b.Cleanup(benchsuite.Suite.TearDownSuite)
|
||||
|
||||
b.Run("PutGetEmptyFiles", benchsuite.BenchmarkPutGetEmptyFiles)
|
||||
b.Run("PutGet1KBFiles", benchsuite.BenchmarkPutGet1KBFiles)
|
||||
b.Run("PutGet1MBFiles", benchsuite.BenchmarkPutGet1MBFiles)
|
||||
b.Run("PutGet1GBFiles", benchsuite.BenchmarkPutGet1GBFiles)
|
||||
b.Run("StreamEmptyFiles", benchsuite.BenchmarkStreamEmptyFiles)
|
||||
b.Run("Stream1KBFiles", benchsuite.BenchmarkStream1KBFiles)
|
||||
b.Run("Stream1MBFiles", benchsuite.BenchmarkStream1MBFiles)
|
||||
b.Run("Stream1GBFiles", benchsuite.BenchmarkStream1GBFiles)
|
||||
b.Run("List5Files", benchsuite.BenchmarkList5Files)
|
||||
b.Run("List50Files", benchsuite.BenchmarkList50Files)
|
||||
b.Run("Delete5Files", benchsuite.BenchmarkDelete5Files)
|
||||
b.Run("Delete50Files", benchsuite.BenchmarkDelete50Files)
|
||||
}
|
||||
|
||||
func TestEmptyRootList(t *testing.T) {
|
||||
if skipS3() != "" {
|
||||
t.Skip(skipS3())
|
||||
|
163
registry/storage/driver/testsuites/benchsuites.go
Normal file
163
registry/storage/driver/testsuites/benchsuites.go
Normal file
@@ -0,0 +1,163 @@
|
||||
package testsuites
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"io"
|
||||
"path"
|
||||
"testing"
|
||||
)
|
||||
|
||||
type DriverBenchmarkSuite struct {
|
||||
Suite *DriverSuite
|
||||
}
|
||||
|
||||
func NewDriverBenchmarkSuite(ds *DriverSuite) *DriverBenchmarkSuite {
|
||||
return &DriverBenchmarkSuite{Suite: ds}
|
||||
}
|
||||
|
||||
// BenchmarkPutGetEmptyFiles benchmarks PutContent/GetContent for 0B files
|
||||
func (s *DriverBenchmarkSuite) BenchmarkPutGetEmptyFiles(b *testing.B) {
|
||||
s.benchmarkPutGetFiles(b, 0)
|
||||
}
|
||||
|
||||
// BenchmarkPutGet1KBFiles benchmarks PutContent/GetContent for 1KB files
|
||||
func (s *DriverBenchmarkSuite) BenchmarkPutGet1KBFiles(b *testing.B) {
|
||||
s.benchmarkPutGetFiles(b, 1024)
|
||||
}
|
||||
|
||||
// BenchmarkPutGet1MBFiles benchmarks PutContent/GetContent for 1MB files
|
||||
func (s *DriverBenchmarkSuite) BenchmarkPutGet1MBFiles(b *testing.B) {
|
||||
s.benchmarkPutGetFiles(b, 1024*1024)
|
||||
}
|
||||
|
||||
// BenchmarkPutGet1GBFiles benchmarks PutContent/GetContent for 1GB files
|
||||
func (s *DriverBenchmarkSuite) BenchmarkPutGet1GBFiles(b *testing.B) {
|
||||
s.benchmarkPutGetFiles(b, 1024*1024*1024)
|
||||
}
|
||||
|
||||
func (s *DriverBenchmarkSuite) benchmarkPutGetFiles(b *testing.B, size int64) {
|
||||
b.SetBytes(size)
|
||||
parentDir := randomPath(8)
|
||||
defer func() {
|
||||
b.StopTimer()
|
||||
// nolint:errcheck
|
||||
s.Suite.StorageDriver.Delete(s.Suite.ctx, firstPart(parentDir))
|
||||
}()
|
||||
|
||||
for i := 0; i < b.N; i++ {
|
||||
filename := path.Join(parentDir, randomPath(32))
|
||||
err := s.Suite.StorageDriver.PutContent(s.Suite.ctx, filename, randomContents(size))
|
||||
s.Suite.Require().NoError(err)
|
||||
|
||||
_, err = s.Suite.StorageDriver.GetContent(s.Suite.ctx, filename)
|
||||
s.Suite.Require().NoError(err)
|
||||
}
|
||||
}
|
||||
|
||||
// BenchmarkStreamEmptyFiles benchmarks Writer/Reader for 0B files
|
||||
func (s *DriverBenchmarkSuite) BenchmarkStreamEmptyFiles(b *testing.B) {
|
||||
s.benchmarkStreamFiles(b, 0)
|
||||
}
|
||||
|
||||
// BenchmarkStream1KBFiles benchmarks Writer/Reader for 1KB files
|
||||
func (s *DriverBenchmarkSuite) BenchmarkStream1KBFiles(b *testing.B) {
|
||||
s.benchmarkStreamFiles(b, 1024)
|
||||
}
|
||||
|
||||
// BenchmarkStream1MBFiles benchmarks Writer/Reader for 1MB files
|
||||
func (s *DriverBenchmarkSuite) BenchmarkStream1MBFiles(b *testing.B) {
|
||||
s.benchmarkStreamFiles(b, 1024*1024)
|
||||
}
|
||||
|
||||
// BenchmarkStream1GBFiles benchmarks Writer/Reader for 1GB files
|
||||
func (s *DriverBenchmarkSuite) BenchmarkStream1GBFiles(b *testing.B) {
|
||||
s.benchmarkStreamFiles(b, 1024*1024*1024)
|
||||
}
|
||||
|
||||
func (s *DriverBenchmarkSuite) benchmarkStreamFiles(b *testing.B, size int64) {
|
||||
b.SetBytes(size)
|
||||
parentDir := randomPath(8)
|
||||
defer func() {
|
||||
b.StopTimer()
|
||||
// nolint:errcheck
|
||||
s.Suite.StorageDriver.Delete(s.Suite.ctx, firstPart(parentDir))
|
||||
}()
|
||||
|
||||
for i := 0; i < b.N; i++ {
|
||||
filename := path.Join(parentDir, randomPath(32))
|
||||
writer, err := s.Suite.StorageDriver.Writer(s.Suite.ctx, filename, false)
|
||||
s.Suite.Require().NoError(err)
|
||||
written, err := io.Copy(writer, bytes.NewReader(randomContents(size)))
|
||||
s.Suite.Require().NoError(err)
|
||||
s.Suite.Require().Equal(size, written)
|
||||
|
||||
err = writer.Commit(context.Background())
|
||||
s.Suite.Require().NoError(err)
|
||||
err = writer.Close()
|
||||
s.Suite.Require().NoError(err)
|
||||
|
||||
rc, err := s.Suite.StorageDriver.Reader(s.Suite.ctx, filename, 0)
|
||||
s.Suite.Require().NoError(err)
|
||||
rc.Close()
|
||||
}
|
||||
}
|
||||
|
||||
// BenchmarkList5Files benchmarks List for 5 small files
|
||||
func (s *DriverBenchmarkSuite) BenchmarkList5Files(b *testing.B) {
|
||||
s.benchmarkListFiles(b, 5)
|
||||
}
|
||||
|
||||
// BenchmarkList50Files benchmarks List for 50 small files
|
||||
func (s *DriverBenchmarkSuite) BenchmarkList50Files(b *testing.B) {
|
||||
s.benchmarkListFiles(b, 50)
|
||||
}
|
||||
|
||||
func (s *DriverBenchmarkSuite) benchmarkListFiles(b *testing.B, numFiles int64) {
|
||||
parentDir := randomPath(8)
|
||||
defer func() {
|
||||
b.StopTimer()
|
||||
// nolint:errcheck
|
||||
s.Suite.StorageDriver.Delete(s.Suite.ctx, firstPart(parentDir))
|
||||
}()
|
||||
|
||||
for i := int64(0); i < numFiles; i++ {
|
||||
err := s.Suite.StorageDriver.PutContent(s.Suite.ctx, path.Join(parentDir, randomPath(32)), nil)
|
||||
s.Suite.Require().NoError(err)
|
||||
}
|
||||
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
files, err := s.Suite.StorageDriver.List(s.Suite.ctx, parentDir)
|
||||
s.Suite.Require().NoError(err)
|
||||
s.Suite.Require().Equal(numFiles, int64(len(files)))
|
||||
}
|
||||
}
|
||||
|
||||
// BenchmarkDelete5Files benchmarks Delete for 5 small files
|
||||
func (s *DriverBenchmarkSuite) BenchmarkDelete5Files(b *testing.B) {
|
||||
s.benchmarkDeleteFiles(b, 5)
|
||||
}
|
||||
|
||||
// BenchmarkDelete50Files benchmarks Delete for 50 small files
|
||||
func (s *DriverBenchmarkSuite) BenchmarkDelete50Files(b *testing.B) {
|
||||
s.benchmarkDeleteFiles(b, 50)
|
||||
}
|
||||
|
||||
func (s *DriverBenchmarkSuite) benchmarkDeleteFiles(b *testing.B, numFiles int64) {
|
||||
for i := 0; i < b.N; i++ {
|
||||
parentDir := randomPath(8)
|
||||
defer s.Suite.deletePath(firstPart(parentDir))
|
||||
|
||||
b.StopTimer()
|
||||
for j := int64(0); j < numFiles; j++ {
|
||||
err := s.Suite.StorageDriver.PutContent(s.Suite.ctx, path.Join(parentDir, randomPath(32)), nil)
|
||||
s.Suite.Require().NoError(err)
|
||||
}
|
||||
b.StartTimer()
|
||||
|
||||
// This is the operation we're benchmarking
|
||||
err := s.Suite.StorageDriver.Delete(s.Suite.ctx, firstPart(parentDir))
|
||||
s.Suite.Require().NoError(err)
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user