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