Skip to content

Commit 2ddb359

Browse files
authored
Adding small test update for temp dir using t.TempDir (#13293)
* Adding small test update for temp dir using t.TempDir Signed-off-by: Mile Druzijanic <[email protected]> Signed-off-by: Mile Druzijanic <[email protected]> * removing not required cleanup Signed-off-by: Mile Druzijanic <[email protected]> --------- Signed-off-by: Mile Druzijanic <[email protected]> Signed-off-by: Mile Druzijanic <[email protected]>
1 parent 6b8e945 commit 2ddb359

File tree

2 files changed

+4
-11
lines changed

2 files changed

+4
-11
lines changed

promql/engine_test.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import (
1818
"errors"
1919
"fmt"
2020
"math"
21-
"os"
2221
"sort"
2322
"testing"
2423
"time"
@@ -47,9 +46,7 @@ func TestMain(m *testing.M) {
4746
func TestQueryConcurrency(t *testing.T) {
4847
maxConcurrency := 10
4948

50-
dir, err := os.MkdirTemp("", "test_concurrency")
51-
require.NoError(t, err)
52-
defer os.RemoveAll(dir)
49+
dir := t.TempDir()
5350
queryTracker := NewActiveQueryTracker(dir, maxConcurrency, nil)
5451
t.Cleanup(queryTracker.Close)
5552

tsdb/tsdbutil/dir_locker_testutil.go

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,8 @@ func TestDirLockerUsage(t *testing.T, open func(t *testing.T, data string, creat
6060

6161
for _, c := range cases {
6262
t.Run(fmt.Sprintf("%+v", c), func(t *testing.T) {
63-
tmpdir, err := os.MkdirTemp("", "test")
64-
require.NoError(t, err)
65-
t.Cleanup(func() {
66-
require.NoError(t, os.RemoveAll(tmpdir))
67-
})
68-
63+
tmpdir := t.TempDir()
64+
6965
// Test preconditions (file already exists + lockfile option)
7066
if c.fileAlreadyExists {
7167
tmpLocker, err := NewDirLocker(tmpdir, "tsdb", log.NewNopLogger(), nil)
@@ -82,7 +78,7 @@ func TestDirLockerUsage(t *testing.T, open func(t *testing.T, data string, creat
8278

8379
// Check that the lockfile is always deleted
8480
if !c.lockFileDisabled {
85-
_, err = os.Stat(locker.path)
81+
_, err := os.Stat(locker.path)
8682
require.True(t, os.IsNotExist(err), "lockfile was not deleted")
8783
}
8884
})

0 commit comments

Comments
 (0)