client: refactor plugin api client functions to define options/results structs

Co-authored-by: Claude <noreply@anthropic.com>
Signed-off-by: Austin Vazquez <austin.vazquez@docker.com>
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Austin Vazquez
2025-10-21 19:13:45 -05:00
committed by Sebastiaan van Stijn
parent eddf1a1ad6
commit 909e32b27d
36 changed files with 427 additions and 162 deletions

View File

@@ -164,18 +164,18 @@ func deleteAllNetworks(ctx context.Context, t testing.TB, c client.NetworkAPICli
func deleteAllPlugins(ctx context.Context, t testing.TB, c client.PluginAPIClient, protectedPlugins map[string]struct{}) {
t.Helper()
plugins, err := c.PluginList(ctx, client.PluginListOptions{})
res, err := c.PluginList(ctx, client.PluginListOptions{})
// Docker EE does not allow cluster-wide plugin management.
if cerrdefs.IsNotImplemented(err) {
return
}
assert.Check(t, err, "failed to list plugins")
for _, p := range plugins {
for _, p := range res.Items {
if _, ok := protectedPlugins[p.Name]; ok {
continue
}
err := c.PluginRemove(ctx, p.Name, client.PluginRemoveOptions{Force: true})
_, err := c.PluginRemove(ctx, p.Name, client.PluginRemoveOptions{Force: true})
assert.Check(t, err, "failed to remove plugin %s", p.ID)
}
}

View File

@@ -194,7 +194,7 @@ func ProtectPlugins(ctx context.Context, t testing.TB, testEnv *Execution) {
func getExistingPlugins(ctx context.Context, t testing.TB, testEnv *Execution) []string {
t.Helper()
apiClient := testEnv.APIClient()
pluginList, err := apiClient.PluginList(ctx, client.PluginListOptions{})
res, err := apiClient.PluginList(ctx, client.PluginListOptions{})
// Docker EE does not allow cluster-wide plugin management.
if cerrdefs.IsNotImplemented(err) {
return []string{}
@@ -202,7 +202,7 @@ func getExistingPlugins(ctx context.Context, t testing.TB, testEnv *Execution) [
assert.NilError(t, err, "failed to list plugins")
var plugins []string
for _, plugin := range pluginList {
for _, plugin := range res.Items {
plugins = append(plugins, plugin.Name)
}
return plugins

View File

@@ -51,7 +51,7 @@ func WithBinary(bin string) CreateOpt {
// CreateClient is the interface used for `BuildPlugin` to interact with the
// daemon.
type CreateClient interface {
PluginCreate(context.Context, io.Reader, client.PluginCreateOptions) error
PluginCreate(context.Context, io.Reader, client.PluginCreateOptions) (client.PluginCreateResult, error)
}
// Create creates a new plugin with the specified name
@@ -71,7 +71,8 @@ func Create(ctx context.Context, c CreateClient, name string, opts ...CreateOpt)
ctx, cancel := context.WithTimeout(ctx, 30*time.Second)
defer cancel()
return c.PluginCreate(ctx, tar, client.PluginCreateOptions{RepoName: name})
_, err = c.PluginCreate(ctx, tar, client.PluginCreateOptions{RepoName: name})
return err
}
// CreateInRegistry makes a plugin (locally) and pushes it to a registry.