]> Sergey Matveev's repositories - btrtrc.git/commitdiff
data/file: Add a test checking for io.ErrUnexpectedEOF on short read
authorMatt Joiner <anacrolix@gmail.com>
Sat, 26 Mar 2016 07:30:30 +0000 (18:30 +1100)
committerMatt Joiner <anacrolix@gmail.com>
Sat, 26 Mar 2016 07:30:30 +0000 (18:30 +1100)
data/file/file_test.go [new file with mode: 0644]

diff --git a/data/file/file_test.go b/data/file/file_test.go
new file mode 100644 (file)
index 0000000..52e345b
--- /dev/null
@@ -0,0 +1,32 @@
+package file
+
+import (
+       "bytes"
+       "io"
+       "io/ioutil"
+       "os"
+       "path/filepath"
+       "testing"
+
+       "github.com/stretchr/testify/assert"
+       "github.com/stretchr/testify/require"
+
+       "github.com/anacrolix/torrent/metainfo"
+)
+
+func TestShortFile(t *testing.T) {
+       td, err := ioutil.TempDir("", "")
+       require.NoError(t, err)
+       defer os.RemoveAll(td)
+       data := TorrentData(&metainfo.Info{
+               Name:   "a",
+               Length: 2,
+       }, td)
+       f, err := os.Create(filepath.Join(td, "a"))
+       err = f.Truncate(1)
+       f.Close()
+       var buf bytes.Buffer
+       n, err := io.Copy(&buf, io.NewSectionReader(data, 0, 2))
+       assert.EqualValues(t, 1, n)
+       assert.Equal(t, io.ErrUnexpectedEOF, err)
+}