2016-07-10 21:03:59 +08:00
|
|
|
package storage
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2018-11-02 20:12:01 +08:00
|
|
|
"github.com/stretchr/testify/require"
|
2019-08-21 18:58:40 +08:00
|
|
|
|
|
|
|
"github.com/anacrolix/torrent/metainfo"
|
2016-07-10 21:03:59 +08:00
|
|
|
)
|
|
|
|
|
2020-02-21 11:12:44 +08:00
|
|
|
func testMarkedCompleteMissingOnRead(t *testing.T, csf func(string) ClientImplCloser) {
|
2022-02-02 15:26:46 +08:00
|
|
|
td := t.TempDir()
|
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)
|
2017-10-12 13:09:32 +08:00
|
|
|
require.False(t, p.Completion().Complete)
|
2016-07-10 21:03:59 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestMarkedCompleteMissingOnReadFile(t *testing.T) {
|
|
|
|
testMarkedCompleteMissingOnRead(t, NewFile)
|
|
|
|
}
|
2016-08-31 15:48:50 +08:00
|
|
|
|
|
|
|
func TestMarkedCompleteMissingOnReadFileBoltDB(t *testing.T) {
|
|
|
|
testMarkedCompleteMissingOnRead(t, NewBoltDB)
|
|
|
|
}
|