testutil, integration: use types/registry.AuthConfig

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn 2022-03-03 10:33:08 +01:00
parent d817f4dcee
commit 2b7416ef34
No known key found for this signature in database
GPG Key ID: 76698F39D527CE8C
3 changed files with 12 additions and 10 deletions

View File

@ -17,6 +17,7 @@ import (
"github.com/containerd/containerd/images" "github.com/containerd/containerd/images"
"github.com/containerd/containerd/remotes/docker" "github.com/containerd/containerd/remotes/docker"
"github.com/docker/docker/api/types" "github.com/docker/docker/api/types"
registrytypes "github.com/docker/docker/api/types/registry"
"github.com/docker/docker/pkg/jsonmessage" "github.com/docker/docker/pkg/jsonmessage"
"github.com/docker/docker/testutil/daemon" "github.com/docker/docker/testutil/daemon"
"github.com/docker/docker/testutil/fixtures/plugin" "github.com/docker/docker/testutil/fixtures/plugin"
@ -125,7 +126,7 @@ func TestPluginInstall(t *testing.T) {
name := "test-" + strings.ToLower(t.Name()) name := "test-" + strings.ToLower(t.Name())
repo := path.Join(registry.DefaultURL, name+":latest") repo := path.Join(registry.DefaultURL, name+":latest")
auth := &types.AuthConfig{ServerAddress: registry.DefaultURL, Username: "testuser", Password: "testpassword"} auth := &registrytypes.AuthConfig{ServerAddress: registry.DefaultURL, Username: "testuser", Password: "testpassword"}
assert.NilError(t, plugin.CreateInRegistry(ctx, repo, auth)) assert.NilError(t, plugin.CreateInRegistry(ctx, repo, auth))
authEncoded, err := json.Marshal(auth) authEncoded, err := json.Marshal(auth)

View File

@ -5,9 +5,9 @@ import (
"fmt" "fmt"
"testing" "testing"
"github.com/docker/docker/api/types" "github.com/docker/docker/api/types/registry"
"github.com/docker/docker/integration/internal/requirement" "github.com/docker/docker/integration/internal/requirement"
"github.com/docker/docker/registry" registrypkg "github.com/docker/docker/registry"
"gotest.tools/v3/assert" "gotest.tools/v3/assert"
is "gotest.tools/v3/assert/cmp" is "gotest.tools/v3/assert/cmp"
"gotest.tools/v3/skip" "gotest.tools/v3/skip"
@ -20,12 +20,12 @@ func TestLoginFailsWithBadCredentials(t *testing.T) {
defer setupTest(t)() defer setupTest(t)()
client := testEnv.APIClient() client := testEnv.APIClient()
config := types.AuthConfig{ config := registry.AuthConfig{
Username: "no-user", Username: "no-user",
Password: "no-password", Password: "no-password",
} }
_, err := client.RegistryLogin(context.Background(), config) _, err := client.RegistryLogin(context.Background(), config)
assert.Assert(t, err != nil) assert.Assert(t, err != nil)
assert.Check(t, is.ErrorContains(err, "unauthorized: incorrect username or password")) assert.Check(t, is.ErrorContains(err, "unauthorized: incorrect username or password"))
assert.Check(t, is.ErrorContains(err, fmt.Sprintf("https://%s/v2/", registry.DefaultRegistryHost))) assert.Check(t, is.ErrorContains(err, fmt.Sprintf("https://%s/v2/", registrypkg.DefaultRegistryHost)))
} }

View File

@ -10,9 +10,10 @@ import (
"time" "time"
"github.com/docker/docker/api/types" "github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/registry"
"github.com/docker/docker/pkg/archive" "github.com/docker/docker/pkg/archive"
"github.com/docker/docker/plugin" "github.com/docker/docker/plugin"
"github.com/docker/docker/registry" registrypkg "github.com/docker/docker/registry"
"github.com/pkg/errors" "github.com/pkg/errors"
) )
@ -26,7 +27,7 @@ type CreateOpt func(*Config)
type Config struct { type Config struct {
*types.PluginConfig *types.PluginConfig
binPath string binPath string
RegistryConfig registry.ServiceOptions RegistryConfig registrypkg.ServiceOptions
} }
// WithInsecureRegistry specifies that the given registry can skip host-key checking as well as fall back to plain http // WithInsecureRegistry specifies that the given registry can skip host-key checking as well as fall back to plain http
@ -77,7 +78,7 @@ func Create(ctx context.Context, c CreateClient, name string, opts ...CreateOpt)
// This can be useful when testing plugins on swarm where you don't really want // This can be useful when testing plugins on swarm where you don't really want
// the plugin to exist on any of the daemons (immediately) and there needs to be // the plugin to exist on any of the daemons (immediately) and there needs to be
// some way to distribute the plugin. // some way to distribute the plugin.
func CreateInRegistry(ctx context.Context, repo string, auth *types.AuthConfig, opts ...CreateOpt) error { func CreateInRegistry(ctx context.Context, repo string, auth *registry.AuthConfig, opts ...CreateOpt) error {
tmpDir, err := os.MkdirTemp("", "create-test-plugin-local") tmpDir, err := os.MkdirTemp("", "create-test-plugin-local")
if err != nil { if err != nil {
return err return err
@ -105,7 +106,7 @@ func CreateInRegistry(ctx context.Context, repo string, auth *types.AuthConfig,
return nil, nil return nil, nil
} }
regService, err := registry.NewService(cfg.RegistryConfig) regService, err := registrypkg.NewService(cfg.RegistryConfig)
if err != nil { if err != nil {
return err return err
} }
@ -130,7 +131,7 @@ func CreateInRegistry(ctx context.Context, repo string, auth *types.AuthConfig,
} }
if auth == nil { if auth == nil {
auth = &types.AuthConfig{} auth = &registry.AuthConfig{}
} }
err = manager.Push(ctx, repo, nil, auth, io.Discard) err = manager.Push(ctx, repo, nil, auth, io.Discard)
return errors.Wrap(err, "error pushing plugin") return errors.Wrap(err, "error pushing plugin")