diff --git a/rules/manager_test.go b/rules/manager_test.go index e7f9c0084..26aa3b2c8 100644 --- a/rules/manager_test.go +++ b/rules/manager_test.go @@ -17,7 +17,6 @@ import ( "context" "fmt" "io/fs" - "io/ioutil" "math" "os" "path" @@ -834,7 +833,7 @@ func TestUpdateSetsSourceTenants(t *testing.T) { rgs, errs := rulefmt.ParseFile("fixtures/rules_with_source_tenants.yaml") require.Empty(t, errs, "file parsing failures") - tmpFile, err := ioutil.TempFile("", "rules.test.*.yaml") + tmpFile, err := os.CreateTemp("", "rules.test.*.yaml") require.NoError(t, err) defer os.Remove(tmpFile.Name()) defer tmpFile.Close() @@ -882,7 +881,7 @@ func TestGroupEvaluationContextFuncIsCalledWhenSupplied(t *testing.T) { rgs, errs := rulefmt.ParseFile("fixtures/rules_with_source_tenants.yaml") require.Empty(t, errs, "file parsing failures") - tmpFile, err := ioutil.TempFile("", "rules.test.*.yaml") + tmpFile, err := os.CreateTemp("", "rules.test.*.yaml") require.NoError(t, err) defer os.Remove(tmpFile.Name()) defer tmpFile.Close() @@ -1540,7 +1539,7 @@ groups: dir := t.TempDir() fname := path.Join(dir, "rules.yaml") - err := ioutil.WriteFile(fname, []byte(config), fs.ModePerm) + err := os.WriteFile(fname, []byte(config), fs.ModePerm) require.NoError(t, err) m := NewManager(&ManagerOptions{ diff --git a/tsdb/chunks/old_head_chunks_test.go b/tsdb/chunks/old_head_chunks_test.go index d81ef3df2..834e427e1 100644 --- a/tsdb/chunks/old_head_chunks_test.go +++ b/tsdb/chunks/old_head_chunks_test.go @@ -16,7 +16,6 @@ package chunks import ( "encoding/binary" "errors" - "io/ioutil" "math/rand" "os" "strconv" @@ -108,7 +107,7 @@ func TestOldChunkDiskMapper_WriteChunk_Chunk_IterateChunks(t *testing.T) { require.Equal(t, 3, len(hrw.mmappedChunkFiles), "expected 3 mmapped files, got %d", len(hrw.mmappedChunkFiles)) require.Equal(t, len(hrw.mmappedChunkFiles), len(hrw.closers)) - actualBytes, err := ioutil.ReadFile(firstFileName) + actualBytes, err := os.ReadFile(firstFileName) require.NoError(t, err) // Check header of the segment file. @@ -224,7 +223,7 @@ func TestOldChunkDiskMapper_Truncate(t *testing.T) { verifyFiles := func(remainingFiles []int) { t.Helper() - files, err := ioutil.ReadDir(hrw.dir.Name()) + files, err := os.ReadDir(hrw.dir.Name()) require.NoError(t, err) require.Equal(t, len(remainingFiles), len(files), "files on disk") require.Equal(t, len(remainingFiles), len(hrw.mmappedChunkFiles), "hrw.mmappedChunkFiles") @@ -322,7 +321,7 @@ func TestOldChunkDiskMapper_Truncate_PreservesFileSequence(t *testing.T) { verifyFiles := func(remainingFiles []int) { t.Helper() - files, err := ioutil.ReadDir(hrw.dir.Name()) + files, err := os.ReadDir(hrw.dir.Name()) require.NoError(t, err) require.Equal(t, len(remainingFiles), len(files), "files on disk") require.Equal(t, len(remainingFiles), len(hrw.mmappedChunkFiles), "hrw.mmappedChunkFiles") @@ -448,7 +447,7 @@ func TestOldChunkDiskMapper_ReadRepairOnEmptyLastFile(t *testing.T) { } // Removed even from disk. - files, err := ioutil.ReadDir(dir) + files, err := os.ReadDir(dir) require.NoError(t, err) require.Equal(t, 3, len(files)) for _, fi := range files { @@ -459,11 +458,7 @@ func TestOldChunkDiskMapper_ReadRepairOnEmptyLastFile(t *testing.T) { } func testOldChunkDiskMapper(t *testing.T) *OldChunkDiskMapper { - tmpdir, err := ioutil.TempDir("", "data") - require.NoError(t, err) - t.Cleanup(func() { - require.NoError(t, os.RemoveAll(tmpdir)) - }) + tmpdir := t.TempDir() hrw, err := NewOldChunkDiskMapper(tmpdir, chunkenc.NewPool(), DefaultWriteBufferSize) require.NoError(t, err) diff --git a/tsdb/compact_test.go b/tsdb/compact_test.go index 3a063c4bd..e02438d3e 100644 --- a/tsdb/compact_test.go +++ b/tsdb/compact_test.go @@ -17,7 +17,6 @@ import ( "context" "crypto/rand" "fmt" - "io/ioutil" "math" "os" "path" @@ -503,7 +502,7 @@ func TestCompaction_CompactWithSplitting(t *testing.T) { shardCounts := []uint64{1, 13} for _, series := range seriesCounts { - dir, err := ioutil.TempDir("", "compact") + dir, err := os.MkdirTemp("", "compact") require.NoError(t, err) defer func() { require.NoError(t, os.RemoveAll(dir)) @@ -623,7 +622,7 @@ func TestCompaction_CompactWithSplitting(t *testing.T) { } func TestCompaction_CompactEmptyBlocks(t *testing.T) { - dir, err := ioutil.TempDir("", "compact") + dir, err := os.MkdirTemp("", "compact") require.NoError(t, err) defer func() { require.NoError(t, os.RemoveAll(dir)) diff --git a/tsdb/index/index_test.go b/tsdb/index/index_test.go index 629fce894..44a0a1614 100644 --- a/tsdb/index/index_test.go +++ b/tsdb/index/index_test.go @@ -608,7 +608,7 @@ func BenchmarkReader_ShardedPostings(b *testing.B) { numShards = 16 ) - dir, err := ioutil.TempDir("", "benchmark_reader_sharded_postings") + dir, err := os.MkdirTemp("", "benchmark_reader_sharded_postings") require.NoError(b, err) defer func() { require.NoError(b, os.RemoveAll(dir))