From 07679c38950ab4b712194b7b48451586787996a0 Mon Sep 17 00:00:00 2001 From: Matt Joiner Date: Mon, 18 Sep 2017 12:14:16 +1000 Subject: [PATCH] Remove test temporary directories when finished They're all grouped together in a parent directory that gets removed. Testing with mmap storage can generate very large files on bad filesystems. --- client_test.go | 15 +++++---------- main_test.go | 14 ++++++++++++++ 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/client_test.go b/client_test.go index 2804d9c8..7324c499 100644 --- a/client_test.go +++ b/client_test.go @@ -6,7 +6,6 @@ import ( "fmt" "io" "io/ioutil" - "log" "math/rand" "net" "os" @@ -32,23 +31,19 @@ import ( "github.com/anacrolix/torrent/storage" ) -func init() { - log.SetFlags(log.LstdFlags | log.Llongfile) -} - func TestingConfig() *Config { return &Config{ - ListenAddr: "localhost:0", - NoDHT: true, - DisableTrackers: true, + ListenAddr: "localhost:0", + NoDHT: true, DataDir: func() string { - ret, err := ioutil.TempDir("", "") + ret, err := ioutil.TempDir(tempDir, "") if err != nil { panic(err) } return ret }(), - Debug: true, + DisableTrackers: true, + Debug: true, } } diff --git a/main_test.go b/main_test.go index b6e46230..b86d42fc 100644 --- a/main_test.go +++ b/main_test.go @@ -1,12 +1,26 @@ package torrent import ( + "io/ioutil" + "log" "os" "testing" ) +var tempDir string + +func init() { + log.SetFlags(log.LstdFlags | log.Llongfile) + var err error + tempDir, err = ioutil.TempDir("", "torrent.test") + if err != nil { + panic(err) + } +} + func TestMain(m *testing.M) { code := m.Run() + os.RemoveAll(tempDir) // select {} os.Exit(code) } -- 2.44.0