mirror of
https://github.com/prometheus/prometheus.git
synced 2025-03-05 20:59:13 -08:00
cmd: use t.TempDir instead of ioutil.TempDir on tests (#9852)
This commit is contained in:
parent
17a92ca6a8
commit
d9a8c453a0
|
@ -288,12 +288,7 @@ func TestMaxBlockChunkSegmentSizeBounds(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestTimeMetrics(t *testing.T) {
|
func TestTimeMetrics(t *testing.T) {
|
||||||
tmpDir, err := ioutil.TempDir("", "time_metrics_e2e")
|
tmpDir := t.TempDir()
|
||||||
require.NoError(t, err)
|
|
||||||
|
|
||||||
defer func() {
|
|
||||||
require.NoError(t, os.RemoveAll(tmpDir))
|
|
||||||
}()
|
|
||||||
|
|
||||||
reg := prometheus.NewRegistry()
|
reg := prometheus.NewRegistry()
|
||||||
db, err := openDBWithMetrics(tmpDir, log.NewNopLogger(), reg, nil, nil)
|
db, err := openDBWithMetrics(tmpDir, log.NewNopLogger(), reg, nil, nil)
|
||||||
|
|
|
@ -248,11 +248,7 @@ func (p *queryLogTest) run(t *testing.T) {
|
||||||
p.setQueryLog(t, "")
|
p.setQueryLog(t, "")
|
||||||
}
|
}
|
||||||
|
|
||||||
dir, err := ioutil.TempDir("", "query_log_test")
|
dir := t.TempDir()
|
||||||
require.NoError(t, err)
|
|
||||||
defer func() {
|
|
||||||
require.NoError(t, os.RemoveAll(dir))
|
|
||||||
}()
|
|
||||||
|
|
||||||
params := append([]string{
|
params := append([]string{
|
||||||
"-test.main",
|
"-test.main",
|
||||||
|
|
|
@ -15,9 +15,7 @@ package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"io/ioutil"
|
|
||||||
"math"
|
"math"
|
||||||
"os"
|
|
||||||
"sort"
|
"sort"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
@ -687,13 +685,9 @@ after_eof 1 2
|
||||||
t.Run(test.Description, func(t *testing.T) {
|
t.Run(test.Description, func(t *testing.T) {
|
||||||
t.Logf("Test:%s", test.Description)
|
t.Logf("Test:%s", test.Description)
|
||||||
|
|
||||||
outputDir, err := ioutil.TempDir("", "myDir")
|
outputDir := t.TempDir()
|
||||||
require.NoError(t, err)
|
|
||||||
defer func() {
|
|
||||||
require.NoError(t, os.RemoveAll(outputDir))
|
|
||||||
}()
|
|
||||||
|
|
||||||
err = backfill(test.MaxSamplesInAppender, []byte(test.ToParse), outputDir, false, false, test.MaxBlockDuration)
|
err := backfill(test.MaxSamplesInAppender, []byte(test.ToParse), outputDir, false, false, test.MaxBlockDuration)
|
||||||
|
|
||||||
if !test.IsOk {
|
if !test.IsOk {
|
||||||
require.Error(t, err, test.Description)
|
require.Error(t, err, test.Description)
|
||||||
|
|
|
@ -17,7 +17,6 @@ import (
|
||||||
"context"
|
"context"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"math"
|
"math"
|
||||||
"os"
|
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
@ -72,11 +71,7 @@ func TestBackfillRuleIntegration(t *testing.T) {
|
||||||
}
|
}
|
||||||
for _, tt := range testCases {
|
for _, tt := range testCases {
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
tmpDir, err := ioutil.TempDir("", "backfilldata")
|
tmpDir := t.TempDir()
|
||||||
require.NoError(t, err)
|
|
||||||
defer func() {
|
|
||||||
require.NoError(t, os.RemoveAll(tmpDir))
|
|
||||||
}()
|
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
|
|
||||||
// Execute the test more than once to simulate running the rule importer twice with the same data.
|
// Execute the test more than once to simulate running the rule importer twice with the same data.
|
||||||
|
@ -219,11 +214,7 @@ func createMultiRuleTestFiles(path string) error {
|
||||||
// TestBackfillLabels confirms that the labels in the rule file override the labels from the metrics
|
// TestBackfillLabels confirms that the labels in the rule file override the labels from the metrics
|
||||||
// received from Prometheus Query API, including the __name__ label.
|
// received from Prometheus Query API, including the __name__ label.
|
||||||
func TestBackfillLabels(t *testing.T) {
|
func TestBackfillLabels(t *testing.T) {
|
||||||
tmpDir, err := ioutil.TempDir("", "backfilldata")
|
tmpDir := t.TempDir()
|
||||||
require.NoError(t, err)
|
|
||||||
defer func() {
|
|
||||||
require.NoError(t, os.RemoveAll(tmpDir))
|
|
||||||
}()
|
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
|
|
||||||
start := time.Date(2009, time.November, 10, 6, 34, 0, 0, time.UTC)
|
start := time.Date(2009, time.November, 10, 6, 34, 0, 0, time.UTC)
|
||||||
|
|
Loading…
Reference in a new issue