Finish fixing tests

This commit is contained in:
Matt Joiner 2016-03-29 00:24:00 +11:00
parent a5b54f21a1
commit 0a3a5d6ae0
5 changed files with 15 additions and 18 deletions

View File

@ -71,6 +71,6 @@ func main() {
if err != nil { if err != nil {
log.Fatal(err) 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()))
} }
} }

View File

@ -49,7 +49,7 @@ type rootNode struct {
type node struct { type node struct {
path string path string
metadata *metainfo.Info metadata *metainfo.InfoEx
FS *TorrentFS FS *TorrentFS
t torrent.Torrent t torrent.Torrent
} }

View File

@ -22,9 +22,9 @@ import (
netContext "golang.org/x/net/context" netContext "golang.org/x/net/context"
"github.com/anacrolix/torrent" "github.com/anacrolix/torrent"
"github.com/anacrolix/torrent/data/mmap"
"github.com/anacrolix/torrent/internal/testutil" "github.com/anacrolix/torrent/internal/testutil"
"github.com/anacrolix/torrent/metainfo" "github.com/anacrolix/torrent/metainfo"
"github.com/anacrolix/torrent/storage"
) )
func init() { func init() {
@ -184,7 +184,7 @@ func TestDownloadOnDemand(t *testing.T) {
require.NoError(t, err) require.NoError(t, err)
defer seeder.Close() defer seeder.Close()
testutil.ExportStatusWriter(seeder, "s") 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) require.NoError(t, err)
leecher, err := torrent.NewClient(&torrent.Config{ leecher, err := torrent.NewClient(&torrent.Config{
DisableTrackers: true, DisableTrackers: true,
@ -194,10 +194,7 @@ func TestDownloadOnDemand(t *testing.T) {
NoDefaultBlocklist: true, NoDefaultBlocklist: true,
TorrentDataOpener: func(info *metainfo.Info) torrent.Storage { DefaultStorage: storage.NewMMap(filepath.Join(layout.BaseDir, "download")),
ret, _ := mmap.TorrentData(info, filepath.Join(layout.BaseDir, "download"))
return ret
},
// This can be used to check if clients can connect to other clients // This can be used to check if clients can connect to other clients
// with the same ID. // with the same ID.

View File

@ -259,7 +259,7 @@ func (mi *MetaInfo) SetDefaults() {
type InfoHash [20]byte type InfoHash [20]byte
func (me *InfoHash) Bytes() []byte { func (me InfoHash) Bytes() []byte {
return me[:] return me[:]
} }
@ -267,6 +267,6 @@ func (ih *InfoHash) AsString() string {
return string(ih[:]) return string(ih[:])
} }
func (ih *InfoHash) HexString() string { func (ih InfoHash) HexString() string {
return fmt.Sprintf("%x", ih[:]) return fmt.Sprintf("%x", ih[:])
} }

View File

@ -27,11 +27,11 @@ type Event struct {
MagnetURI string MagnetURI string
Change Change
TorrentFilePath string TorrentFilePath string
InfoHash torrent.InfoHash InfoHash metainfo.InfoHash
} }
type entity struct { type entity struct {
torrent.InfoHash metainfo.InfoHash
MagnetURI string MagnetURI string
TorrentFilePath string TorrentFilePath string
} }
@ -40,7 +40,7 @@ type Instance struct {
w *fsnotify.Watcher w *fsnotify.Watcher
dirName string dirName string
Events chan Event Events chan Event
dirState map[torrent.InfoHash]entity dirState map[metainfo.InfoHash]entity
} }
func (me *Instance) Close() { 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) mi, _ := metainfo.LoadFromFile(fileName)
if mi == nil { if mi == nil {
return return
@ -75,7 +75,7 @@ func torrentFileInfoHash(fileName string) (ih torrent.InfoHash, ok bool) {
return return
} }
func scanDir(dirName string) (ee map[torrent.InfoHash]entity) { func scanDir(dirName string) (ee map[metainfo.InfoHash]entity) {
d, err := os.Open(dirName) d, err := os.Open(dirName)
if err != nil { if err != nil {
log.Print(err) log.Print(err)
@ -87,7 +87,7 @@ func scanDir(dirName string) (ee map[torrent.InfoHash]entity) {
log.Print(err) log.Print(err)
return return
} }
ee = make(map[torrent.InfoHash]entity, len(names)) ee = make(map[metainfo.InfoHash]entity, len(names))
addEntity := func(e entity) { addEntity := func(e entity) {
e0, ok := ee[e.InfoHash] e0, ok := ee[e.InfoHash]
if ok { if ok {
@ -151,7 +151,7 @@ func magnetFileURIs(name string) (uris []string, err error) {
return return
} }
func (me *Instance) torrentRemoved(ih torrent.InfoHash) { func (me *Instance) torrentRemoved(ih metainfo.InfoHash) {
me.Events <- Event{ me.Events <- Event{
InfoHash: ih, InfoHash: ih,
Change: Removed, Change: Removed,
@ -203,7 +203,7 @@ func New(dirName string) (i *Instance, err error) {
w: w, w: w,
dirName: dirName, dirName: dirName,
Events: make(chan Event), Events: make(chan Event),
dirState: make(map[torrent.InfoHash]entity, 0), dirState: make(map[metainfo.InfoHash]entity, 0),
} }
go func() { go func() {
i.refresh() i.refresh()