mirror of
https://github.com/distribution/distribution.git
synced 2025-09-16 07:09:49 +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
@@ -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)
|
||||
}
|
||||
|
Reference in New Issue
Block a user