Skip to content
Snippets Groups Projects
Commit a14c0c1a authored by Pawel Rozlach's avatar Pawel Rozlach
Browse files

test: rewrite middleware tests from gocheck to testify/suite

parent c0e96378
No related branches found
No related tags found
1 merge request!1846test: rewrite middleware tests to testify/suite, finish removal of gocheck code
......@@ -26,7 +26,7 @@ middleware:storage-googlecdn:
variables:
TEST_SHORT_FLAG: ""
- when: always
script: $GO_TEST -timeout=$TEST_TIMEOUT -v -coverprofile=coverage.out -tags=$BUILDTAGS $PACKAGE -args -check.v $TEST_SHORT_FLAG
script: $GO_TEST -timeout=$TEST_TIMEOUT -v -coverprofile=coverage.out -tags=$BUILDTAGS $PACKAGE $TEST_SHORT_FLAG
filesystem:
<<: *storage-driver-test
......@@ -41,7 +41,7 @@ inmemory:
PACKAGE: 'github.com/docker/distribution/registry/storage/driver/inmemory'
# Always run short tests for in-memory driver or we might run out of memory
# and cause a flaky test https://gitlab.com/gitlab-org/container-registry/-/issues/1177
script: $GO_TEST -timeout=$TEST_TIMEOUT -v -coverprofile=coverage.out -tags=$BUILDTAGS $PACKAGE -args -check.v -test.short
script: $GO_TEST -timeout=$TEST_TIMEOUT -v -coverprofile=coverage.out -tags=$BUILDTAGS $PACKAGE -test.short
s3-aws:
<<: *storage-driver-test
......
......@@ -39,7 +39,7 @@ docker run --network=host -t --entrypoint=/bin/sh minio/mc \
Now you can run the S3 integration tests against the MinIO server we created above:
```shell
go test -timeout 20m -v github.com/docker/distribution/registry/storage/driver/s3-aws -args -check.v
go test -timeout 20m -v github.com/docker/distribution/registry/storage/driver/s3-aws
```
Finally, the MinIO server can be stopped once you are finished with the
......@@ -55,7 +55,7 @@ To run the benchmarks against any configured driver, run the following
command, substituting the appropriate driver:
```shell
go test -v -cpuprofile profile.out github.com/docker/distribution/registry/storage/driver/s3-aws -args -check.v -check.b
go test -v -cpuprofile profile.out github.com/docker/distribution/registry/storage/driver/s3-aws
```
Afterwards, the `profile.out` file we generated above can be used to analyze
......
......@@ -46,7 +46,6 @@ require (
golang.org/x/sync v0.8.0
golang.org/x/time v0.7.0
google.golang.org/api v0.200.0
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c
gopkg.in/yaml.v2 v2.4.0
)
......@@ -105,8 +104,6 @@ require (
github.com/jackc/puddle/v2 v2.2.2 // indirect
github.com/jmespath/go-jmespath v0.4.0 // indirect
github.com/klauspost/compress v1.17.9 // indirect
github.com/kr/pretty v0.3.1 // indirect
github.com/kr/text v0.2.0 // indirect
github.com/kylelemons/godebug v1.1.0 // indirect
github.com/magiconair/properties v1.8.7 // indirect
github.com/mattn/go-runewidth v0.0.16 // indirect
......@@ -121,7 +118,6 @@ require (
github.com/prometheus/common v0.55.0 // indirect
github.com/prometheus/procfs v0.15.1 // indirect
github.com/rivo/uniseg v0.4.7 // indirect
github.com/rogpeppe/go-internal v1.10.0 // indirect
github.com/sagikazarmark/locafero v0.4.0 // indirect
github.com/sagikazarmark/slog-shim v0.1.0 // indirect
github.com/sebest/xff v0.0.0-20210106013422-671bd2870b3a // indirect
......
......@@ -170,7 +170,6 @@ github.com/coreos/pkg v0.0.0-20160727233714-3ac0863d7acf/go.mod h1:E3G3o1h8I7cfc
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
github.com/cpuguy83/go-md2man/v2 v2.0.4/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/creack/pty v1.1.7/go.mod h1:lj5s0c3V2DBrqTV7llrYr5NG6My20zk30Fl46Y7DoTY=
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM=
......@@ -435,7 +434,6 @@ github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxv
github.com/konsorten/go-windows-terminal-sequences v1.0.3/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
......@@ -532,7 +530,6 @@ github.com/pierrec/lz4 v1.0.2-0.20190131084431-473cd7ce01a1/go.mod h1:3/3N9NVKO0
github.com/pierrec/lz4 v2.0.5+incompatible/go.mod h1:pdkljMzZIN41W+lC3N2tnIh5sFi+IEE17M5jbnwPHcY=
github.com/pingcap/errors v0.11.4 h1:lFuQV/oaUMGcD2tqt+01ROSmJs75VG1ToEOkZIZ4nE4=
github.com/pingcap/errors v0.11.4/go.mod h1:Oi8TUi2kEtXXLMJk9l1cGmz20kV3TaQ0usTwv5KuLY8=
github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA=
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
......@@ -592,7 +589,6 @@ github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUc
github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6SoW27p1b0cqNHllgS5HIMJraePCO15w5zCzIWYg=
github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ=
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs=
github.com/rogpeppe/go-internal v1.10.0 h1:TMyTOH3F/DB16zRVcYyreMH6GnZZrwQVAoYjRBZyWFQ=
github.com/rogpeppe/go-internal v1.10.0/go.mod h1:UQnix2H7Ngw/k4C5ijL5+65zddjncjaFoBhdsK/akog=
github.com/rubenv/sql-migrate v1.7.0 h1:HtQq1xyTN2ISmQDggnh0c9U3JlP8apWh8YO2jzlXpTI=
......
......@@ -4,22 +4,25 @@ import (
"os"
"testing"
check "gopkg.in/check.v1"
"github.com/stretchr/testify/require"
"github.com/stretchr/testify/suite"
)
func Test(t *testing.T) { check.TestingT(t) }
type MiddlewareSuite struct{}
func TestCloudfrontMiddlewareSuite(t *testing.T) {
suite.Run(t, new(CloudfrontMiddlewareSuite))
}
var _ = check.Suite(&MiddlewareSuite{})
type CloudfrontMiddlewareSuite struct {
suite.Suite
}
func (s *MiddlewareSuite) TestNoConfig(c *check.C) {
func (suite *CloudfrontMiddlewareSuite) TestNoConfig() {
options := make(map[string]interface{})
_, err := newCloudFrontStorageMiddleware(nil, options)
c.Assert(err, check.ErrorMatches, "no baseurl provided")
require.ErrorContains(suite.T(), err, "no baseurl provided")
}
func TestCloudFrontStorageMiddlewareGenerateKey(t *testing.T) {
func (suite *CloudfrontMiddlewareSuite) TestCloudFrontStorageMiddlewareGenerateKey() {
options := make(map[string]interface{})
options["baseurl"] = "example.com"
......@@ -41,18 +44,13 @@ pZeMRablbPQdp8/1NyIwimq1VlG0ohQ4P6qhW7E09ZMC
`
file, err := os.CreateTemp("", "pkey")
if err != nil {
t.Fatal("File cannot be created")
}
require.NoErrorf(suite.T(), err, "File cannot be created")
file.WriteString(privk)
defer os.Remove(file.Name())
options["privatekey"] = file.Name()
options["keypairid"] = "test"
storageDriver, err := newCloudFrontStorageMiddleware(nil, options)
if err != nil {
t.Fatal(err)
}
if storageDriver == nil {
t.Fatal("Driver couldnt be initialized.")
}
require.NoError(suite.T(), err)
require.NotNil(suite.T(), storageDriver, "Driver couldnt be initialized")
}
......@@ -4,56 +4,59 @@ import (
"context"
"testing"
check "gopkg.in/check.v1"
"github.com/stretchr/testify/require"
"github.com/stretchr/testify/suite"
)
func Test(t *testing.T) { check.TestingT(t) }
type MiddlewareSuite struct{}
func TestRedirectMiddlewareSuite(t *testing.T) {
suite.Run(t, new(RedirectMiddlewareSuite))
}
var _ = check.Suite(&MiddlewareSuite{})
type RedirectMiddlewareSuite struct {
suite.Suite
}
func (s *MiddlewareSuite) TestNoConfig(c *check.C) {
func (suite *RedirectMiddlewareSuite) TestNoConfig() {
options := make(map[string]interface{})
_, err := newRedirectStorageMiddleware(nil, options)
c.Assert(err, check.ErrorMatches, "no baseurl provided")
require.ErrorContains(suite.T(), err, "no baseurl provided")
}
func (s *MiddlewareSuite) TestMissingScheme(c *check.C) {
func (suite *RedirectMiddlewareSuite) TestMissingScheme() {
options := make(map[string]interface{})
options["baseurl"] = "example.com"
_, err := newRedirectStorageMiddleware(nil, options)
c.Assert(err, check.ErrorMatches, "no scheme specified for redirect baseurl")
require.ErrorContains(suite.T(), err, "no scheme specified for redirect baseurl")
}
func (s *MiddlewareSuite) TestHttpsPort(c *check.C) {
func (suite *RedirectMiddlewareSuite) TestHttpsPort() {
options := make(map[string]interface{})
options["baseurl"] = "https://example.com:5443"
middleware, err := newRedirectStorageMiddleware(nil, options)
c.Assert(err, check.Equals, nil)
require.NoError(suite.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(suite.T(), ok)
require.Equal(suite.T(), "https", m.scheme)
require.Equal(suite.T(), "example.com:5443", m.host)
url, err := middleware.URLFor(context.TODO(), "/rick/data", nil)
c.Assert(err, check.Equals, nil)
c.Assert(url, check.Equals, "https://example.com:5443/rick/data")
require.NoError(suite.T(), err)
require.Equal(suite.T(), "https://example.com:5443/rick/data", url)
}
func (s *MiddlewareSuite) TestHTTP(c *check.C) {
func (suite *RedirectMiddlewareSuite) TestHTTP() {
options := make(map[string]interface{})
options["baseurl"] = "http://example.com"
middleware, err := newRedirectStorageMiddleware(nil, options)
c.Assert(err, check.Equals, nil)
require.NoError(suite.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(suite.T(), ok)
require.Equal(suite.T(), "http", m.scheme)
require.Equal(suite.T(), "example.com", m.host)
url, err := middleware.URLFor(context.TODO(), "morty/data", nil)
c.Assert(err, check.Equals, nil)
c.Assert(url, check.Equals, "http://example.com/morty/data")
require.NoError(suite.T(), err)
require.Equal(suite.T(), "http://example.com/morty/data", url)
}
......@@ -1123,7 +1123,7 @@ func (suite *DriverSuite) TestStatCall() {
require.Greaterf(
suite.T(),
modTime,
createdTime,
createdTime,
"modtime (%s) is before the creation time (%s)", modTime, createdTime,
)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment