]> Sergey Matveev's repositories - btrtrc.git/blob - storage/file_test.go
Remove the InfoEx type, and don't generate its infohash on the fly
[btrtrc.git] / storage / file_test.go
1 package storage
2
3 import (
4         "bytes"
5         "io"
6         "io/ioutil"
7         "os"
8         "path/filepath"
9         "testing"
10
11         "github.com/anacrolix/missinggo"
12         "github.com/stretchr/testify/assert"
13         "github.com/stretchr/testify/require"
14
15         "github.com/anacrolix/torrent/metainfo"
16 )
17
18 func TestShortFile(t *testing.T) {
19         td, err := ioutil.TempDir("", "")
20         require.NoError(t, err)
21         defer os.RemoveAll(td)
22         s := NewFile(td)
23         info := &metainfo.Info{
24                 Name:        "a",
25                 Length:      2,
26                 PieceLength: missinggo.MiB,
27         }
28         ts, err := s.OpenTorrent(info, metainfo.Hash{})
29         assert.NoError(t, err)
30         f, err := os.Create(filepath.Join(td, "a"))
31         err = f.Truncate(1)
32         f.Close()
33         var buf bytes.Buffer
34         p := info.Piece(0)
35         n, err := io.Copy(&buf, io.NewSectionReader(ts.Piece(p), 0, p.Length()))
36         assert.EqualValues(t, 1, n)
37         assert.Equal(t, io.ErrUnexpectedEOF, err)
38 }