]> Sergey Matveev's repositories - btrtrc.git/blobdiff - storage/file_test.go
Fixes for storage tests on Windows
[btrtrc.git] / storage / file_test.go
index 5c63c94cecd5c50a4769db25ce4eddc37e1622a6..a6c69fa28dfef0ac12a6095d582c4ca58f1355da 100644 (file)
@@ -3,12 +3,11 @@ package storage
 import (
        "bytes"
        "io"
-       "io/ioutil"
        "os"
        "path/filepath"
        "testing"
 
-       "github.com/anacrolix/missinggo"
+       "github.com/anacrolix/missinggo/v2"
        "github.com/stretchr/testify/assert"
        "github.com/stretchr/testify/require"
 
@@ -16,10 +15,9 @@ import (
 )
 
 func TestShortFile(t *testing.T) {
-       td, err := ioutil.TempDir("", "")
-       require.NoError(t, err)
-       defer os.RemoveAll(td)
+       td := t.TempDir()
        s := NewFile(td)
+       defer s.Close()
        info := &metainfo.Info{
                Name:        "a",
                Length:      2,
@@ -28,11 +26,17 @@ func TestShortFile(t *testing.T) {
        ts, err := s.OpenTorrent(info, metainfo.Hash{})
        assert.NoError(t, err)
        f, err := os.Create(filepath.Join(td, "a"))
+       require.NoError(t, err)
        err = f.Truncate(1)
+       require.NoError(t, err)
        f.Close()
        var buf bytes.Buffer
        p := info.Piece(0)
        n, err := io.Copy(&buf, io.NewSectionReader(ts.Piece(p), 0, p.Length()))
        assert.EqualValues(t, 1, n)
-       assert.Equal(t, io.ErrUnexpectedEOF, err)
+       switch err {
+       case nil, io.EOF:
+       default:
+               t.Errorf("expected nil or EOF error from truncated piece, got %v", err)
+       }
 }