]> Sergey Matveev's repositories - btrtrc.git/blobdiff - internal/testutil/spec.go
chore: remove refs to deprecated io/ioutil
[btrtrc.git] / internal / testutil / spec.go
index c3e5cd8821338d87b643770c6f8f663385b46f55..63e4a74c633f646bdb1efa7c1607684cf0b807d9 100644 (file)
@@ -2,10 +2,10 @@ package testutil
 
 import (
        "io"
-       "io/ioutil"
        "strings"
 
-       "github.com/anacrolix/missinggo/assert"
+       "github.com/anacrolix/missinggo/expect"
+
        "github.com/anacrolix/torrent/bencode"
        "github.com/anacrolix/torrent/metainfo"
 )
@@ -43,11 +43,18 @@ func (t *Torrent) Info(pieceLength int64) metainfo.Info {
        }
        if t.IsDir() {
                info.Length = int64(len(t.Files[0].Data))
+       } else {
+               for _, f := range t.Files {
+                       info.Files = append(info.Files, metainfo.FileInfo{
+                               Path:   []string{f.Name},
+                               Length: int64(len(f.Data)),
+                       })
+               }
        }
        err := info.GeneratePieces(func(fi metainfo.FileInfo) (io.ReadCloser, error) {
-               return ioutil.NopCloser(strings.NewReader(t.GetFile(strings.Join(fi.Path, "/")).Data)), nil
+               return io.NopCloser(strings.NewReader(t.GetFile(strings.Join(fi.Path, "/")).Data)), nil
        })
-       assert.Nil(err)
+       expect.Nil(err)
        return info
 }
 
@@ -55,6 +62,6 @@ func (t *Torrent) Metainfo(pieceLength int64) *metainfo.MetaInfo {
        mi := metainfo.MetaInfo{}
        var err error
        mi.InfoBytes, err = bencode.Marshal(t.Info(pieceLength))
-       assert.Nil(err)
+       expect.Nil(err)
        return &mi
 }