mirror of
https://github.com/prometheus/prometheus.git
synced 2024-12-24 05:04:05 -08:00
Remove use of io/ioutil.
This commit is contained in:
parent
9d51bf50db
commit
d051065441
|
@ -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{
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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))
|
||||
|
|
|
@ -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))
|
||||
|
|
Loading…
Reference in a new issue