2016-07-10 20:58:43 +08:00
|
|
|
package torrent
|
|
|
|
|
|
|
|
import (
|
2017-09-18 10:14:16 +08:00
|
|
|
"io/ioutil"
|
|
|
|
"log"
|
2016-07-10 20:58:43 +08:00
|
|
|
"os"
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
2017-11-07 13:00:08 +08:00
|
|
|
// A top-level temp dir that lasts for the duration of the package tests, and
|
|
|
|
// is removed at completion.
|
|
|
|
var pkgTempDir string
|
2017-09-18 10:14:16 +08:00
|
|
|
|
|
|
|
func init() {
|
|
|
|
log.SetFlags(log.LstdFlags | log.Llongfile)
|
|
|
|
var err error
|
2017-11-07 13:00:08 +08:00
|
|
|
pkgTempDir, err = ioutil.TempDir("", "torrent.test")
|
2017-09-18 10:14:16 +08:00
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-07 13:00:08 +08:00
|
|
|
func tempDir() string {
|
|
|
|
ret, err := ioutil.TempDir(pkgTempDir, "")
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
return ret
|
|
|
|
}
|
|
|
|
|
2016-07-10 20:58:43 +08:00
|
|
|
func TestMain(m *testing.M) {
|
|
|
|
code := m.Run()
|
2017-11-07 13:00:08 +08:00
|
|
|
os.RemoveAll(pkgTempDir)
|
2016-07-10 20:58:43 +08:00
|
|
|
// select {}
|
|
|
|
os.Exit(code)
|
|
|
|
}
|