From 6f6ef1451eccf758a835bcad64a2098b994938f1 Mon Sep 17 00:00:00 2001 From: Li Zhijian Date: Mon, 24 Aug 2020 15:33:22 +0800 Subject: [PATCH] Cleanup tempfiles (#7696) * cleanup tempfiles for web_test Signed-off-by: Li Zhijian * cleanup tempfiles for api_test Signed-off-by: Li Zhijian * cleanup tempfiles for file_test Signed-off-by: Li Zhijian --- pkg/logging/file_test.go | 14 ++++++++++---- web/api/v1/api_test.go | 2 +- web/web_test.go | 4 ++-- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/pkg/logging/file_test.go b/pkg/logging/file_test.go index 4974db3cc..a2eb20961 100644 --- a/pkg/logging/file_test.go +++ b/pkg/logging/file_test.go @@ -24,9 +24,12 @@ import ( ) func TestJSONFileLogger_basic(t *testing.T) { - f, err := ioutil.TempFile("", "") + f, err := ioutil.TempFile("", "logging") 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()) testutil.Ok(t, err) @@ -50,9 +53,12 @@ func TestJSONFileLogger_basic(t *testing.T) { } func TestJSONFileLogger_parallel(t *testing.T) { - f, err := ioutil.TempFile("", "") + f, err := ioutil.TempFile("", "logging") 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()) testutil.Ok(t, err) diff --git a/web/api/v1/api_test.go b/web/api/v1/api_test.go index 4f2e5ac3a..94d26db77 100644 --- a/web/api/v1/api_test.go +++ b/web/api/v1/api_test.go @@ -2291,7 +2291,7 @@ func TestAdminEndpoints(t *testing.T) { tc := tc t.Run("", func(t *testing.T) { dir, _ := ioutil.TempDir("", "fakeDB") - defer testutil.Ok(t, os.RemoveAll(dir)) + defer func() { testutil.Ok(t, os.RemoveAll(dir)) }() api := &API{ db: tc.db, diff --git a/web/web_test.go b/web/web_test.go index a721e3050..cc33e1e8e 100644 --- a/web/web_test.go +++ b/web/web_test.go @@ -104,7 +104,7 @@ func TestReadyAndHealthy(t *testing.T) { dbDir, err := ioutil.TempDir("", "tsdb-ready") 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) testutil.Ok(t, err) @@ -298,7 +298,7 @@ func TestRoutePrefix(t *testing.T) { t.Parallel() dbDir, err := ioutil.TempDir("", "tsdb-ready") 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) testutil.Ok(t, err)