From 02e800dcbb64effd3a9d6136ef7a2bb23695e6a8 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Tue, 22 Apr 2025 10:53:56 +0200 Subject: [PATCH] plugin: use t.TempDir Signed-off-by: Sebastiaan van Stijn --- plugin/backend_linux_test.go | 18 +++--------------- plugin/manager_linux_test.go | 8 +++----- 2 files changed, 6 insertions(+), 20 deletions(-) diff --git a/plugin/backend_linux_test.go b/plugin/backend_linux_test.go index 59e8a37a65..07fdba56a5 100644 --- a/plugin/backend_linux_test.go +++ b/plugin/backend_linux_test.go @@ -7,11 +7,7 @@ import ( ) func TestAtomicRemoveAllNormal(t *testing.T) { - dir, err := os.MkdirTemp("", "atomic-remove-with-normal") - if err != nil { - t.Fatal(err) - } - defer os.RemoveAll(dir) // just try to make sure this gets cleaned up + dir := t.TempDir() if err := atomicRemoveAll(dir); err != nil { t.Fatal(err) @@ -26,11 +22,7 @@ func TestAtomicRemoveAllNormal(t *testing.T) { } func TestAtomicRemoveAllAlreadyExists(t *testing.T) { - dir, err := os.MkdirTemp("", "atomic-remove-already-exists") - if err != nil { - t.Fatal(err) - } - defer os.RemoveAll(dir) // just try to make sure this gets cleaned up + dir := t.TempDir() if err := os.MkdirAll(dir+"-removing", 0o755); err != nil { t.Fatal(err) @@ -54,11 +46,7 @@ func TestAtomicRemoveAllNotExist(t *testing.T) { t.Fatal(err) } - dir, err := os.MkdirTemp("", "atomic-remove-already-exists") - if err != nil { - t.Fatal(err) - } - defer os.RemoveAll(dir) // just try to make sure this gets cleaned up + dir := t.TempDir() // create the removing dir, but not the "real" one foo := filepath.Join(dir, "foo") diff --git a/plugin/manager_linux_test.go b/plugin/manager_linux_test.go index f26781ee71..342a481927 100644 --- a/plugin/manager_linux_test.go +++ b/plugin/manager_linux_test.go @@ -23,11 +23,9 @@ import ( func TestManagerWithPluginMounts(t *testing.T) { skip.If(t, os.Getuid() != 0, "skipping test that requires root") - root, err := os.MkdirTemp("", "test-store-with-plugin-mounts") - if err != nil { - t.Fatal(err) - } - defer containerfs.EnsureRemoveAll(root) + + root := t.TempDir() + t.Cleanup(func() { _ = containerfs.EnsureRemoveAll(root) }) s := NewStore() managerRoot := filepath.Join(root, "manager")