2
0
mirror of synced 2025-02-23 22:28:11 +00:00

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.
This commit is contained in:
Matt Joiner 2017-09-18 12:14:16 +10:00
parent bb53c97d38
commit 07679c3895
2 changed files with 19 additions and 10 deletions

View File

@ -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,
}
}

View File

@ -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)
}