mirror of
https://github.com/docker/cli.git
synced 2026-01-06 05:41:44 +03:00
e2e/testutils: SetupPlugin: return path of directory
The gotest.tools `fs.NewDir` utility already sets up a `t.Cleanup`, so we can treat it the same as `t.TempDir()` and let it handle cleaning up by itself. We should probably consider replacing some of this with `t.TempDir`. Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
@@ -146,11 +146,10 @@ func TestPromptExitCode(t *testing.T) {
|
||||
skip.If(t, versions.LessThan(environment.DaemonAPIVersion(t), "1.44"))
|
||||
|
||||
pluginDir := testutils.SetupPlugin(t, ctx)
|
||||
t.Cleanup(pluginDir.Remove)
|
||||
|
||||
plugin := "registry:5000/plugin-content-trust-install:latest"
|
||||
|
||||
icmd.RunCommand("docker", "plugin", "create", plugin, pluginDir.Path()).Assert(t, icmd.Success)
|
||||
icmd.RunCommand("docker", "plugin", "create", plugin, pluginDir).Assert(t, icmd.Success)
|
||||
icmd.RunCmd(icmd.Command("docker", "plugin", "push", plugin), defaultCmdOpts...).Assert(t, icmd.Success)
|
||||
icmd.RunCmd(icmd.Command("docker", "plugin", "rm", "-f", plugin), defaultCmdOpts...).Assert(t, icmd.Success)
|
||||
return icmd.Command("docker", "plugin", "install", plugin)
|
||||
@@ -163,14 +162,12 @@ func TestPromptExitCode(t *testing.T) {
|
||||
skip.If(t, versions.LessThan(environment.DaemonAPIVersion(t), "1.44"))
|
||||
|
||||
pluginLatestDir := testutils.SetupPlugin(t, ctx)
|
||||
t.Cleanup(pluginLatestDir.Remove)
|
||||
pluginNextDir := testutils.SetupPlugin(t, ctx)
|
||||
t.Cleanup(pluginNextDir.Remove)
|
||||
|
||||
plugin := "registry:5000/plugin-content-trust-upgrade"
|
||||
|
||||
icmd.RunCommand("docker", "plugin", "create", plugin+":latest", pluginLatestDir.Path()).Assert(t, icmd.Success)
|
||||
icmd.RunCommand("docker", "plugin", "create", plugin+":next", pluginNextDir.Path()).Assert(t, icmd.Success)
|
||||
icmd.RunCommand("docker", "plugin", "create", plugin+":latest", pluginLatestDir).Assert(t, icmd.Success)
|
||||
icmd.RunCommand("docker", "plugin", "create", plugin+":next", pluginNextDir).Assert(t, icmd.Success)
|
||||
icmd.RunCmd(icmd.Command("docker", "plugin", "push", plugin+":latest"), defaultCmdOpts...).Assert(t, icmd.Success)
|
||||
icmd.RunCmd(icmd.Command("docker", "plugin", "push", plugin+":next"), defaultCmdOpts...).Assert(t, icmd.Success)
|
||||
icmd.RunCmd(icmd.Command("docker", "plugin", "rm", "-f", plugin+":latest"), defaultCmdOpts...).Assert(t, icmd.Success)
|
||||
|
||||
@@ -29,9 +29,8 @@ func TestInstallWithContentTrust(t *testing.T) {
|
||||
t.Cleanup(cancel)
|
||||
|
||||
pluginDir := testutils.SetupPlugin(t, ctx)
|
||||
t.Cleanup(pluginDir.Remove)
|
||||
|
||||
icmd.RunCommand("docker", "plugin", "create", pluginName, pluginDir.Path()).Assert(t, icmd.Success)
|
||||
icmd.RunCommand("docker", "plugin", "create", pluginName, pluginDir).Assert(t, icmd.Success)
|
||||
result := icmd.RunCmd(icmd.Command("docker", "plugin", "push", pluginName),
|
||||
fixtures.WithConfig(dir.Path()),
|
||||
fixtures.WithTrust,
|
||||
|
||||
@@ -22,8 +22,10 @@ import (
|
||||
var plugins embed.FS
|
||||
|
||||
// SetupPlugin builds a plugin and creates a temporary
|
||||
// directory with the plugin's config.json and rootfs.
|
||||
func SetupPlugin(t *testing.T, ctx context.Context) *fs.Dir {
|
||||
// directory with the plugin's config.json and rootfs,
|
||||
// which will be removed in [t.Cleanup]. It returns
|
||||
// the location of the temporary directory.
|
||||
func SetupPlugin(t *testing.T, ctx context.Context) (pluginDir string) {
|
||||
t.Helper()
|
||||
|
||||
p := &plugin.Config{
|
||||
@@ -52,7 +54,7 @@ func SetupPlugin(t *testing.T, ctx context.Context) *fs.Dir {
|
||||
)
|
||||
|
||||
icmd.RunCommand("/bin/cp", binPath, dir.Join("rootfs", p.Entrypoint[0])).Assert(t, icmd.Success)
|
||||
return dir
|
||||
return dir.Path()
|
||||
}
|
||||
|
||||
// buildPlugin uses Go to build a plugin from one of the source files in the plugins directory.
|
||||
|
||||
Reference in New Issue
Block a user