2016-07-10 12:58:43 +00:00
|
|
|
package torrent
|
|
|
|
|
|
|
|
import (
|
2017-09-18 02:14:16 +00:00
|
|
|
"io/ioutil"
|
|
|
|
"log"
|
2016-07-10 12:58:43 +00:00
|
|
|
"os"
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
2017-11-07 05:00:08 +00: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 02:14:16 +00:00
|
|
|
|
|
|
|
func init() {
|
2018-02-11 04:14:31 +00:00
|
|
|
log.SetFlags(log.LstdFlags | log.Lshortfile)
|
2017-09-18 02:14:16 +00:00
|
|
|
var err error
|
2017-11-07 05:00:08 +00:00
|
|
|
pkgTempDir, err = ioutil.TempDir("", "torrent.test")
|
2017-09-18 02:14:16 +00:00
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-07 05:00:08 +00:00
|
|
|
func tempDir() string {
|
|
|
|
ret, err := ioutil.TempDir(pkgTempDir, "")
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
return ret
|
|
|
|
}
|
|
|
|
|
2016-07-10 12:58:43 +00:00
|
|
|
func TestMain(m *testing.M) {
|
|
|
|
code := m.Run()
|
2017-11-07 05:00:08 +00:00
|
|
|
os.RemoveAll(pkgTempDir)
|
2016-07-10 12:58:43 +00:00
|
|
|
// select {}
|
|
|
|
os.Exit(code)
|
|
|
|
}
|