2016-07-10 21:03:59 +08:00
|
|
|
package storage
|
|
|
|
|
|
|
|
import (
|
|
|
|
"io/ioutil"
|
|
|
|
"os"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
|
|
|
|
"github.com/anacrolix/torrent/metainfo"
|
|
|
|
)
|
|
|
|
|
2016-09-02 13:10:57 +08:00
|
|
|
func testMarkedCompleteMissingOnRead(t *testing.T, csf func(string) ClientImpl) {
|
2016-07-10 21:03:59 +08:00
|
|
|
td, err := ioutil.TempDir("", "")
|
|
|
|
require.NoError(t, err)
|
|
|
|
defer os.RemoveAll(td)
|
2016-09-02 13:10:57 +08:00
|
|
|
cs := NewClient(csf(td))
|
2016-08-26 18:29:05 +08:00
|
|
|
info := &metainfo.Info{
|
|
|
|
PieceLength: 1,
|
|
|
|
Files: []metainfo.FileInfo{{Path: []string{"a"}, Length: 1}},
|
2016-07-10 21:03:59 +08:00
|
|
|
}
|
2016-08-26 18:29:05 +08:00
|
|
|
ts, err := cs.OpenTorrent(info, metainfo.Hash{})
|
2016-07-10 21:03:59 +08:00
|
|
|
require.NoError(t, err)
|
|
|
|
p := ts.Piece(info.Piece(0))
|
|
|
|
require.NoError(t, p.MarkComplete())
|
2016-09-02 13:10:57 +08:00
|
|
|
// require.False(t, p.GetIsComplete())
|
2016-07-10 21:03:59 +08:00
|
|
|
n, err := p.ReadAt(make([]byte, 1), 0)
|
|
|
|
require.Error(t, err)
|
|
|
|
require.EqualValues(t, 0, n)
|
|
|
|
require.False(t, p.GetIsComplete())
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestMarkedCompleteMissingOnReadFile(t *testing.T) {
|
|
|
|
testMarkedCompleteMissingOnRead(t, NewFile)
|
|
|
|
}
|
2016-08-31 15:48:50 +08:00
|
|
|
|
|
|
|
func TestMarkedCompleteMissingOnReadFileBoltDB(t *testing.T) {
|
|
|
|
testMarkedCompleteMissingOnRead(t, NewBoltDB)
|
|
|
|
}
|