Remove use of io/ioutil.

This commit is contained in:
Peter Štibraný 2022-06-09 11:49:45 +02:00
parent 9d51bf50db
commit d051065441
4 changed files with 11 additions and 18 deletions

View file

@ -17,7 +17,6 @@ import (
"context" "context"
"fmt" "fmt"
"io/fs" "io/fs"
"io/ioutil"
"math" "math"
"os" "os"
"path" "path"
@ -834,7 +833,7 @@ func TestUpdateSetsSourceTenants(t *testing.T) {
rgs, errs := rulefmt.ParseFile("fixtures/rules_with_source_tenants.yaml") rgs, errs := rulefmt.ParseFile("fixtures/rules_with_source_tenants.yaml")
require.Empty(t, errs, "file parsing failures") 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) require.NoError(t, err)
defer os.Remove(tmpFile.Name()) defer os.Remove(tmpFile.Name())
defer tmpFile.Close() defer tmpFile.Close()
@ -882,7 +881,7 @@ func TestGroupEvaluationContextFuncIsCalledWhenSupplied(t *testing.T) {
rgs, errs := rulefmt.ParseFile("fixtures/rules_with_source_tenants.yaml") rgs, errs := rulefmt.ParseFile("fixtures/rules_with_source_tenants.yaml")
require.Empty(t, errs, "file parsing failures") 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) require.NoError(t, err)
defer os.Remove(tmpFile.Name()) defer os.Remove(tmpFile.Name())
defer tmpFile.Close() defer tmpFile.Close()
@ -1540,7 +1539,7 @@ groups:
dir := t.TempDir() dir := t.TempDir()
fname := path.Join(dir, "rules.yaml") 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) require.NoError(t, err)
m := NewManager(&ManagerOptions{ m := NewManager(&ManagerOptions{

View file

@ -16,7 +16,6 @@ package chunks
import ( import (
"encoding/binary" "encoding/binary"
"errors" "errors"
"io/ioutil"
"math/rand" "math/rand"
"os" "os"
"strconv" "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, 3, len(hrw.mmappedChunkFiles), "expected 3 mmapped files, got %d", len(hrw.mmappedChunkFiles))
require.Equal(t, len(hrw.mmappedChunkFiles), len(hrw.closers)) require.Equal(t, len(hrw.mmappedChunkFiles), len(hrw.closers))
actualBytes, err := ioutil.ReadFile(firstFileName) actualBytes, err := os.ReadFile(firstFileName)
require.NoError(t, err) require.NoError(t, err)
// Check header of the segment file. // Check header of the segment file.
@ -224,7 +223,7 @@ func TestOldChunkDiskMapper_Truncate(t *testing.T) {
verifyFiles := func(remainingFiles []int) { verifyFiles := func(remainingFiles []int) {
t.Helper() t.Helper()
files, err := ioutil.ReadDir(hrw.dir.Name()) files, err := os.ReadDir(hrw.dir.Name())
require.NoError(t, err) require.NoError(t, err)
require.Equal(t, len(remainingFiles), len(files), "files on disk") require.Equal(t, len(remainingFiles), len(files), "files on disk")
require.Equal(t, len(remainingFiles), len(hrw.mmappedChunkFiles), "hrw.mmappedChunkFiles") 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) { verifyFiles := func(remainingFiles []int) {
t.Helper() t.Helper()
files, err := ioutil.ReadDir(hrw.dir.Name()) files, err := os.ReadDir(hrw.dir.Name())
require.NoError(t, err) require.NoError(t, err)
require.Equal(t, len(remainingFiles), len(files), "files on disk") require.Equal(t, len(remainingFiles), len(files), "files on disk")
require.Equal(t, len(remainingFiles), len(hrw.mmappedChunkFiles), "hrw.mmappedChunkFiles") require.Equal(t, len(remainingFiles), len(hrw.mmappedChunkFiles), "hrw.mmappedChunkFiles")
@ -448,7 +447,7 @@ func TestOldChunkDiskMapper_ReadRepairOnEmptyLastFile(t *testing.T) {
} }
// Removed even from disk. // Removed even from disk.
files, err := ioutil.ReadDir(dir) files, err := os.ReadDir(dir)
require.NoError(t, err) require.NoError(t, err)
require.Equal(t, 3, len(files)) require.Equal(t, 3, len(files))
for _, fi := range files { for _, fi := range files {
@ -459,11 +458,7 @@ func TestOldChunkDiskMapper_ReadRepairOnEmptyLastFile(t *testing.T) {
} }
func testOldChunkDiskMapper(t *testing.T) *OldChunkDiskMapper { func testOldChunkDiskMapper(t *testing.T) *OldChunkDiskMapper {
tmpdir, err := ioutil.TempDir("", "data") tmpdir := t.TempDir()
require.NoError(t, err)
t.Cleanup(func() {
require.NoError(t, os.RemoveAll(tmpdir))
})
hrw, err := NewOldChunkDiskMapper(tmpdir, chunkenc.NewPool(), DefaultWriteBufferSize) hrw, err := NewOldChunkDiskMapper(tmpdir, chunkenc.NewPool(), DefaultWriteBufferSize)
require.NoError(t, err) require.NoError(t, err)

View file

@ -17,7 +17,6 @@ import (
"context" "context"
"crypto/rand" "crypto/rand"
"fmt" "fmt"
"io/ioutil"
"math" "math"
"os" "os"
"path" "path"
@ -503,7 +502,7 @@ func TestCompaction_CompactWithSplitting(t *testing.T) {
shardCounts := []uint64{1, 13} shardCounts := []uint64{1, 13}
for _, series := range seriesCounts { for _, series := range seriesCounts {
dir, err := ioutil.TempDir("", "compact") dir, err := os.MkdirTemp("", "compact")
require.NoError(t, err) require.NoError(t, err)
defer func() { defer func() {
require.NoError(t, os.RemoveAll(dir)) require.NoError(t, os.RemoveAll(dir))
@ -623,7 +622,7 @@ func TestCompaction_CompactWithSplitting(t *testing.T) {
} }
func TestCompaction_CompactEmptyBlocks(t *testing.T) { func TestCompaction_CompactEmptyBlocks(t *testing.T) {
dir, err := ioutil.TempDir("", "compact") dir, err := os.MkdirTemp("", "compact")
require.NoError(t, err) require.NoError(t, err)
defer func() { defer func() {
require.NoError(t, os.RemoveAll(dir)) require.NoError(t, os.RemoveAll(dir))

View file

@ -608,7 +608,7 @@ func BenchmarkReader_ShardedPostings(b *testing.B) {
numShards = 16 numShards = 16
) )
dir, err := ioutil.TempDir("", "benchmark_reader_sharded_postings") dir, err := os.MkdirTemp("", "benchmark_reader_sharded_postings")
require.NoError(b, err) require.NoError(b, err)
defer func() { defer func() {
require.NoError(b, os.RemoveAll(dir)) require.NoError(b, os.RemoveAll(dir))