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 GreetingFileContents = "hello, world\n"
25 GreetingFileName = "greeting"
28 func CreateDummyTorrentData(dirName string) string {
29 f, _ := os.Create(filepath.Join(dirName, "greeting"))
31 f.WriteString(GreetingFileContents)
35 func GreetingMetaInfo() *metainfo.MetaInfo {
36 return Greeting.Metainfo(5)
39 // Gives a temporary directory containing the completed "greeting" torrent,
40 // and a corresponding metainfo describing it. The temporary directory can be
41 // cleaned away with os.RemoveAll.
42 func GreetingTestTorrent() (tempDir string, metaInfo *metainfo.MetaInfo) {
43 tempDir, err := ioutil.TempDir(os.TempDir(), "")
47 CreateDummyTorrentData(tempDir)
48 metaInfo = GreetingMetaInfo()