12 "bitbucket.org/anacrolix/go.torrent/testutil"
15 fusefs "bazil.org/fuse/fs"
16 "bitbucket.org/anacrolix/go.torrent"
17 metainfo "github.com/nsf/libtorgo/torrent"
20 func TestTCPAddrString(t *testing.T) {
22 IP: net.IPv4(127, 0, 0, 1),
26 l, err := net.Listen("tcp4", "localhost:3000")
31 c, err := net.Dial("tcp", l.Addr().String())
36 ras := c.RemoteAddr().String()
42 func TestDownloadOnDemand(t *testing.T) {
43 dir, err := ioutil.TempDir("", "torrentfs")
48 if err := os.RemoveAll(dir); err != nil {
52 t.Logf("test directory: %s", dir)
53 finishedDir := filepath.Join(dir, "finished")
54 os.Mkdir(finishedDir, 0777)
55 name := testutil.CreateDummyTorrentData(finishedDir)
56 metaInfoBuf := &bytes.Buffer{}
57 testutil.CreateMetaInfo(name, metaInfoBuf)
58 metaInfo, err := metainfo.Load(metaInfoBuf)
59 seeder := torrent.Client{
61 Listener: func() net.Listener {
62 conn, err := net.Listen("tcp", ":0")
69 defer seeder.Listener.Close()
72 seeder.AddTorrent(metaInfo)
73 leecher := torrent.Client{
74 DataDir: filepath.Join(dir, "download"),
78 leecher.AddTorrent(metaInfo)
79 leecher.AddPeers(torrent.BytesInfoHash(metaInfo.InfoHash), []torrent.Peer{func() torrent.Peer {
80 tcpAddr := seeder.Listener.Addr().(*net.TCPAddr)
86 mountDir := filepath.Join(dir, "mnt")
87 os.Mkdir(mountDir, 0777)
89 fuseConn, err := fuse.Mount(mountDir)
94 if err := fuse.Unmount(mountDir); err != nil {
99 if err := fusefs.Serve(fuseConn, fs); err != nil {
102 if err := fuseConn.Close(); err != nil {
107 if fuseConn.MountError != nil {
108 t.Fatal(fuseConn.MountError)
111 time.Sleep(10 * time.Second)
112 fuse.Unmount(mountDir)
114 content, err := ioutil.ReadFile(filepath.Join(mountDir, "greeting"))
118 if string(content) != testutil.GreetingFileContents {