From: Matt Joiner Date: Mon, 28 Mar 2016 13:24:00 +0000 (+1100) Subject: Finish fixing tests X-Git-Tag: v1.0.0~812 X-Git-Url: http://www.git.stargrave.org/?a=commitdiff_plain;h=0a3a5d6ae00bd47a002a70d3edbe4d7ae78f2027;p=btrtrc.git Finish fixing tests --- diff --git a/cmd/torrent-verify/main.go b/cmd/torrent-verify/main.go index 5ab7d810..f7457b85 100644 --- a/cmd/torrent-verify/main.go +++ b/cmd/torrent-verify/main.go @@ -71,6 +71,6 @@ func main() { if err != nil { log.Fatal(err) } - fmt.Printf("%d: %x: %v\n", i, p.Hash(), bytes.Equal(hash.Sum(nil), p.Hash())) + fmt.Printf("%d: %x: %v\n", i, p.Hash(), bytes.Equal(hash.Sum(nil), p.Hash().Bytes())) } } diff --git a/fs/torrentfs.go b/fs/torrentfs.go index 8e3fca53..abca5c8f 100644 --- a/fs/torrentfs.go +++ b/fs/torrentfs.go @@ -49,7 +49,7 @@ type rootNode struct { type node struct { path string - metadata *metainfo.Info + metadata *metainfo.InfoEx FS *TorrentFS t torrent.Torrent } diff --git a/fs/torrentfs_test.go b/fs/torrentfs_test.go index 7e0c7832..62191c6f 100644 --- a/fs/torrentfs_test.go +++ b/fs/torrentfs_test.go @@ -22,9 +22,9 @@ import ( netContext "golang.org/x/net/context" "github.com/anacrolix/torrent" - "github.com/anacrolix/torrent/data/mmap" "github.com/anacrolix/torrent/internal/testutil" "github.com/anacrolix/torrent/metainfo" + "github.com/anacrolix/torrent/storage" ) func init() { @@ -184,7 +184,7 @@ func TestDownloadOnDemand(t *testing.T) { require.NoError(t, err) defer seeder.Close() testutil.ExportStatusWriter(seeder, "s") - _, err = seeder.AddMagnet(fmt.Sprintf("magnet:?xt=urn:btih:%x", layout.Metainfo.Info.Hash)) + _, err = seeder.AddMagnet(fmt.Sprintf("magnet:?xt=urn:btih:%s", layout.Metainfo.Info.Hash.HexString())) require.NoError(t, err) leecher, err := torrent.NewClient(&torrent.Config{ DisableTrackers: true, @@ -194,10 +194,7 @@ func TestDownloadOnDemand(t *testing.T) { NoDefaultBlocklist: true, - TorrentDataOpener: func(info *metainfo.Info) torrent.Storage { - ret, _ := mmap.TorrentData(info, filepath.Join(layout.BaseDir, "download")) - return ret - }, + DefaultStorage: storage.NewMMap(filepath.Join(layout.BaseDir, "download")), // This can be used to check if clients can connect to other clients // with the same ID. diff --git a/metainfo/metainfo.go b/metainfo/metainfo.go index 87974825..8b99fc3e 100644 --- a/metainfo/metainfo.go +++ b/metainfo/metainfo.go @@ -259,7 +259,7 @@ func (mi *MetaInfo) SetDefaults() { type InfoHash [20]byte -func (me *InfoHash) Bytes() []byte { +func (me InfoHash) Bytes() []byte { return me[:] } @@ -267,6 +267,6 @@ func (ih *InfoHash) AsString() string { return string(ih[:]) } -func (ih *InfoHash) HexString() string { +func (ih InfoHash) HexString() string { return fmt.Sprintf("%x", ih[:]) } diff --git a/util/dirwatch/dirwatch.go b/util/dirwatch/dirwatch.go index 7d87f844..3ae70487 100644 --- a/util/dirwatch/dirwatch.go +++ b/util/dirwatch/dirwatch.go @@ -27,11 +27,11 @@ type Event struct { MagnetURI string Change TorrentFilePath string - InfoHash torrent.InfoHash + InfoHash metainfo.InfoHash } type entity struct { - torrent.InfoHash + metainfo.InfoHash MagnetURI string TorrentFilePath string } @@ -40,7 +40,7 @@ type Instance struct { w *fsnotify.Watcher dirName string Events chan Event - dirState map[torrent.InfoHash]entity + dirState map[metainfo.InfoHash]entity } func (me *Instance) Close() { @@ -65,7 +65,7 @@ func (me *Instance) handleErrors() { } } -func torrentFileInfoHash(fileName string) (ih torrent.InfoHash, ok bool) { +func torrentFileInfoHash(fileName string) (ih metainfo.InfoHash, ok bool) { mi, _ := metainfo.LoadFromFile(fileName) if mi == nil { return @@ -75,7 +75,7 @@ func torrentFileInfoHash(fileName string) (ih torrent.InfoHash, ok bool) { return } -func scanDir(dirName string) (ee map[torrent.InfoHash]entity) { +func scanDir(dirName string) (ee map[metainfo.InfoHash]entity) { d, err := os.Open(dirName) if err != nil { log.Print(err) @@ -87,7 +87,7 @@ func scanDir(dirName string) (ee map[torrent.InfoHash]entity) { log.Print(err) return } - ee = make(map[torrent.InfoHash]entity, len(names)) + ee = make(map[metainfo.InfoHash]entity, len(names)) addEntity := func(e entity) { e0, ok := ee[e.InfoHash] if ok { @@ -151,7 +151,7 @@ func magnetFileURIs(name string) (uris []string, err error) { return } -func (me *Instance) torrentRemoved(ih torrent.InfoHash) { +func (me *Instance) torrentRemoved(ih metainfo.InfoHash) { me.Events <- Event{ InfoHash: ih, Change: Removed, @@ -203,7 +203,7 @@ func New(dirName string) (i *Instance, err error) { w: w, dirName: dirName, Events: make(chan Event), - dirState: make(map[torrent.InfoHash]entity, 0), + dirState: make(map[metainfo.InfoHash]entity, 0), } go func() { i.refresh()