Skip to content

Commit

Permalink
Cleanup tempfiles (prometheus#7696)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
zhijianli88 authored Aug 24, 2020
1 parent 6f9e7ff commit 6f6ef14
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
14 changes: 10 additions & 4 deletions pkg/logging/file_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion web/api/v1/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions web/web_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 6f6ef14

Please sign in to comment.