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:
Li Zhijian 2021-01-15 16:19:57 +08:00 committed by GitHub
parent b82d76faec
commit 9602933db2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 1 deletions

View File

@ -32,6 +32,7 @@ func TestBlockWriter(t *testing.T) {
ctx := context.Background()
outputDir, err := ioutil.TempDir(os.TempDir(), "output")
require.NoError(t, err)
defer func() { require.NoError(t, os.RemoveAll(outputDir)) }()
w, err := NewBlockWriter(log.NewNopLogger(), outputDir, DefaultBlockDuration)
require.NoError(t, err)
@ -55,6 +56,7 @@ func TestBlockWriter(t *testing.T) {
blockpath := filepath.Join(outputDir, id.String())
b, err := OpenBlock(nil, blockpath, nil)
require.NoError(t, err)
defer func() { require.NoError(t, b.Close()) }()
q, err := NewBlockQuerier(b, math.MinInt64, math.MaxInt64)
require.NoError(t, err)
series := query(t, q, labels.MustNewMatcher(labels.MatchRegexp, "", ".*"))

View File

@ -454,8 +454,9 @@ func TestLogPartialWrite(t *testing.T) {
for testName, testData := range tests {
t.Run(testName, func(t *testing.T) {
dirPath, err := ioutil.TempDir("", "")
dirPath, err := ioutil.TempDir("", "logpartialwrite")
require.NoError(t, err)
defer func() { require.NoError(t, os.RemoveAll(dirPath)) }()
w, err := NewSize(nil, nil, dirPath, segmentSize, false)
require.NoError(t, err)
@ -480,6 +481,7 @@ func TestLogPartialWrite(t *testing.T) {
// Read it back. We expect no corruption.
s, err := OpenReadSegment(SegmentName(dirPath, 0))
require.NoError(t, err)
defer func() { require.NoError(t, s.Close()) }()
r := NewReader(NewSegmentBufReader(s))
for i := 0; i < testData.numRecords; i++ {