未验证 提交 9602933d 编写于 作者: L Li Zhijian 提交者: GitHub

Cleanup tempfiles in tests (#8179)

* test: cleanup tempdir for TestBlockWriter
Signed-off-by: NLi Zhijian <lizhijian@cn.fujitsu.com>

* test: cleanup tempdir for TestLogPartialWrite
Signed-off-by: NLi Zhijian <lizhijian@cn.fujitsu.com>
上级 b82d76fa
......@@ -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, "", ".*"))
......
......@@ -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++ {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册