11 "github.com/anacrolix/missinggo"
12 "github.com/stretchr/testify/assert"
13 "github.com/stretchr/testify/require"
15 "github.com/anacrolix/torrent/metainfo"
18 func TestShortFile(t *testing.T) {
19 td, err := ioutil.TempDir("", "")
20 require.NoError(t, err)
21 defer os.RemoveAll(td)
23 info := &metainfo.Info{
26 PieceLength: missinggo.MiB,
28 ts, err := s.OpenTorrent(info, metainfo.Hash{})
29 assert.NoError(t, err)
30 f, err := os.Create(filepath.Join(td, "a"))
31 require.NoError(t, err)
33 require.NoError(t, err)
37 n, err := io.Copy(&buf, io.NewSectionReader(ts.Piece(p), 0, p.Length()))
38 assert.EqualValues(t, 1, n)
42 t.Errorf("expected nil or EOF error from truncated piece, got %v", err)