From cb3b17a14c162cce051ae944d06c2c1a742a9211 Mon Sep 17 00:00:00 2001 From: SuryaPrakash <119923001+suryaaprakassh@users.noreply.github.com> Date: Fri, 31 Jan 2025 20:02:20 +0530 Subject: [PATCH] fix: os.MkdirTemp with t.TempDir (#15860) Signed-off-by: Surya Prakash --- tsdb/tsdbutil/dir_locker_testutil.go | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/tsdb/tsdbutil/dir_locker_testutil.go b/tsdb/tsdbutil/dir_locker_testutil.go index 7228dbafed..5a335989c7 100644 --- a/tsdb/tsdbutil/dir_locker_testutil.go +++ b/tsdb/tsdbutil/dir_locker_testutil.go @@ -60,11 +60,7 @@ func TestDirLockerUsage(t *testing.T, open func(t *testing.T, data string, creat for _, c := range cases { t.Run(fmt.Sprintf("%+v", c), func(t *testing.T) { - tmpdir, err := os.MkdirTemp("", "test") - require.NoError(t, err) - t.Cleanup(func() { - require.NoError(t, os.RemoveAll(tmpdir)) - }) + tmpdir := t.TempDir() // Test preconditions (file already exists + lockfile option) if c.fileAlreadyExists { @@ -82,7 +78,7 @@ func TestDirLockerUsage(t *testing.T, open func(t *testing.T, data string, creat // Check that the lockfile is always deleted if !c.lockFileDisabled { - _, err = os.Stat(locker.path) + _, err := os.Stat(locker.path) require.True(t, os.IsNotExist(err), "lockfile was not deleted") } })