From 081add2fc5093bc631e19f3b767bca2b50c3ee8e Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Tue, 5 Aug 2025 10:18:10 +0200 Subject: [PATCH] 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 --- e2e/global/cli_test.go | 9 +++------ e2e/plugin/trust_test.go | 3 +-- e2e/testutils/plugins.go | 8 +++++--- 3 files changed, 9 insertions(+), 11 deletions(-) diff --git a/e2e/global/cli_test.go b/e2e/global/cli_test.go index 69233a4ef4..89d4d56be4 100644 --- a/e2e/global/cli_test.go +++ b/e2e/global/cli_test.go @@ -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) diff --git a/e2e/plugin/trust_test.go b/e2e/plugin/trust_test.go index 1101ddc64a..663c274ce1 100644 --- a/e2e/plugin/trust_test.go +++ b/e2e/plugin/trust_test.go @@ -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, diff --git a/e2e/testutils/plugins.go b/e2e/testutils/plugins.go index ebacf2cb20..3dde6ba934 100644 --- a/e2e/testutils/plugins.go +++ b/e2e/testutils/plugins.go @@ -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.