Cleanup tempfiles (#7696)

* cleanup tempfiles for web_test

Signed-off-by: Li Zhijian <lizhijian@cn.fujitsu.com>

* cleanup tempfiles for api_test

Signed-off-by: Li Zhijian <lizhijian@cn.fujitsu.com>

* cleanup tempfiles for file_test

Signed-off-by: Li Zhijian <lizhijian@cn.fujitsu.com>
This commit is contained in:
Li Zhijian 2020-08-24 15:33:22 +08:00 committed by GitHub
parent 6f9e7ff750
commit 6f6ef1451e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 7 deletions

View file

@ -24,9 +24,12 @@ import (
) )
func TestJSONFileLogger_basic(t *testing.T) { func TestJSONFileLogger_basic(t *testing.T) {
f, err := ioutil.TempFile("", "") f, err := ioutil.TempFile("", "logging")
testutil.Ok(t, err) testutil.Ok(t, err)
defer f.Close() defer func() {
testutil.Ok(t, f.Close())
testutil.Ok(t, os.Remove(f.Name()))
}()
l, err := NewJSONFileLogger(f.Name()) l, err := NewJSONFileLogger(f.Name())
testutil.Ok(t, err) testutil.Ok(t, err)
@ -50,9 +53,12 @@ func TestJSONFileLogger_basic(t *testing.T) {
} }
func TestJSONFileLogger_parallel(t *testing.T) { func TestJSONFileLogger_parallel(t *testing.T) {
f, err := ioutil.TempFile("", "") f, err := ioutil.TempFile("", "logging")
testutil.Ok(t, err) testutil.Ok(t, err)
defer f.Close() defer func() {
testutil.Ok(t, f.Close())
testutil.Ok(t, os.Remove(f.Name()))
}()
l, err := NewJSONFileLogger(f.Name()) l, err := NewJSONFileLogger(f.Name())
testutil.Ok(t, err) testutil.Ok(t, err)

View file

@ -2291,7 +2291,7 @@ func TestAdminEndpoints(t *testing.T) {
tc := tc tc := tc
t.Run("", func(t *testing.T) { t.Run("", func(t *testing.T) {
dir, _ := ioutil.TempDir("", "fakeDB") dir, _ := ioutil.TempDir("", "fakeDB")
defer testutil.Ok(t, os.RemoveAll(dir)) defer func() { testutil.Ok(t, os.RemoveAll(dir)) }()
api := &API{ api := &API{
db: tc.db, db: tc.db,

View file

@ -104,7 +104,7 @@ func TestReadyAndHealthy(t *testing.T) {
dbDir, err := ioutil.TempDir("", "tsdb-ready") dbDir, err := ioutil.TempDir("", "tsdb-ready")
testutil.Ok(t, err) testutil.Ok(t, err)
defer testutil.Ok(t, os.RemoveAll(dbDir)) defer func() { testutil.Ok(t, os.RemoveAll(dbDir)) }()
db, err := tsdb.Open(dbDir, nil, nil, nil) db, err := tsdb.Open(dbDir, nil, nil, nil)
testutil.Ok(t, err) testutil.Ok(t, err)
@ -298,7 +298,7 @@ func TestRoutePrefix(t *testing.T) {
t.Parallel() t.Parallel()
dbDir, err := ioutil.TempDir("", "tsdb-ready") dbDir, err := ioutil.TempDir("", "tsdb-ready")
testutil.Ok(t, err) testutil.Ok(t, err)
defer testutil.Ok(t, os.RemoveAll(dbDir)) defer func() { testutil.Ok(t, os.RemoveAll(dbDir)) }()
db, err := tsdb.Open(dbDir, nil, nil, nil) db, err := tsdb.Open(dbDir, nil, nil, nil)
testutil.Ok(t, err) testutil.Ok(t, err)