mirror of
https://github.com/prometheus/prometheus.git
synced 2024-11-09 23:24:05 -08:00
Cleanup tempfiles in tests (#8179)
* test: cleanup tempdir for TestBlockWriter Signed-off-by: Li Zhijian <lizhijian@cn.fujitsu.com> * test: cleanup tempdir for TestLogPartialWrite Signed-off-by: Li Zhijian <lizhijian@cn.fujitsu.com>
This commit is contained in:
parent
b82d76faec
commit
9602933db2
|
@ -32,6 +32,7 @@ func TestBlockWriter(t *testing.T) {
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
outputDir, err := ioutil.TempDir(os.TempDir(), "output")
|
outputDir, err := ioutil.TempDir(os.TempDir(), "output")
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
defer func() { require.NoError(t, os.RemoveAll(outputDir)) }()
|
||||||
w, err := NewBlockWriter(log.NewNopLogger(), outputDir, DefaultBlockDuration)
|
w, err := NewBlockWriter(log.NewNopLogger(), outputDir, DefaultBlockDuration)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
@ -55,6 +56,7 @@ func TestBlockWriter(t *testing.T) {
|
||||||
blockpath := filepath.Join(outputDir, id.String())
|
blockpath := filepath.Join(outputDir, id.String())
|
||||||
b, err := OpenBlock(nil, blockpath, nil)
|
b, err := OpenBlock(nil, blockpath, nil)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
defer func() { require.NoError(t, b.Close()) }()
|
||||||
q, err := NewBlockQuerier(b, math.MinInt64, math.MaxInt64)
|
q, err := NewBlockQuerier(b, math.MinInt64, math.MaxInt64)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
series := query(t, q, labels.MustNewMatcher(labels.MatchRegexp, "", ".*"))
|
series := query(t, q, labels.MustNewMatcher(labels.MatchRegexp, "", ".*"))
|
||||||
|
|
|
@ -454,8 +454,9 @@ func TestLogPartialWrite(t *testing.T) {
|
||||||
|
|
||||||
for testName, testData := range tests {
|
for testName, testData := range tests {
|
||||||
t.Run(testName, func(t *testing.T) {
|
t.Run(testName, func(t *testing.T) {
|
||||||
dirPath, err := ioutil.TempDir("", "")
|
dirPath, err := ioutil.TempDir("", "logpartialwrite")
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
defer func() { require.NoError(t, os.RemoveAll(dirPath)) }()
|
||||||
|
|
||||||
w, err := NewSize(nil, nil, dirPath, segmentSize, false)
|
w, err := NewSize(nil, nil, dirPath, segmentSize, false)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
@ -480,6 +481,7 @@ func TestLogPartialWrite(t *testing.T) {
|
||||||
// Read it back. We expect no corruption.
|
// Read it back. We expect no corruption.
|
||||||
s, err := OpenReadSegment(SegmentName(dirPath, 0))
|
s, err := OpenReadSegment(SegmentName(dirPath, 0))
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
defer func() { require.NoError(t, s.Close()) }()
|
||||||
|
|
||||||
r := NewReader(NewSegmentBufReader(s))
|
r := NewReader(NewSegmentBufReader(s))
|
||||||
for i := 0; i < testData.numRecords; i++ {
|
for i := 0; i < testData.numRecords; i++ {
|
||||||
|
|
Loading…
Reference in a new issue