1 // Package testutil contains stuff for testing torrent-related behaviour.
3 // "greeting" is a single-file torrent of a file called "greeting" that
4 // "contains "hello, world\n".
13 "github.com/anacrolix/torrent/metainfo"
16 var Greeting = Torrent{
18 Data: GreetingFileContents,
20 Name: GreetingFileName,
24 // A null in the middle triggers an error if SQLite stores data as text instead of blob.
25 GreetingFileContents = "hello,\x00world\n"
26 GreetingFileName = "greeting"
29 func CreateDummyTorrentData(dirName string) string {
30 f, _ := os.Create(filepath.Join(dirName, "greeting"))
32 f.WriteString(GreetingFileContents)
36 func GreetingMetaInfo() *metainfo.MetaInfo {
37 return Greeting.Metainfo(5)
40 // Gives a temporary directory containing the completed "greeting" torrent,
41 // and a corresponding metainfo describing it. The temporary directory can be
42 // cleaned away with os.RemoveAll.
43 func GreetingTestTorrent() (tempDir string, metaInfo *metainfo.MetaInfo) {
44 tempDir, err := ioutil.TempDir(os.TempDir(), "")
48 CreateDummyTorrentData(tempDir)
49 metaInfo = GreetingMetaInfo()