]> Sergey Matveev's repositories - btrtrc.git/blob - storage/issue96_test.go
go1.19 compat
[btrtrc.git] / storage / issue96_test.go
1 package storage
2
3 import (
4         "testing"
5
6         "github.com/stretchr/testify/require"
7
8         "github.com/anacrolix/torrent/metainfo"
9 )
10
11 func testMarkedCompleteMissingOnRead(t *testing.T, csf func(string) ClientImplCloser) {
12         td := t.TempDir()
13         cic := csf(td)
14         defer cic.Close()
15         cs := NewClient(cic)
16         info := &metainfo.Info{
17                 PieceLength: 1,
18                 Files:       []metainfo.FileInfo{{Path: []string{"a"}, Length: 1}},
19         }
20         ts, err := cs.OpenTorrent(info, metainfo.Hash{})
21         require.NoError(t, err)
22         p := ts.Piece(info.Piece(0))
23         require.NoError(t, p.MarkComplete())
24         // require.False(t, p.GetIsComplete())
25         n, err := p.ReadAt(make([]byte, 1), 0)
26         require.Error(t, err)
27         require.EqualValues(t, 0, n)
28         require.False(t, p.Completion().Complete)
29 }
30
31 func TestMarkedCompleteMissingOnReadFile(t *testing.T) {
32         testMarkedCompleteMissingOnRead(t, NewFile)
33 }
34
35 func TestMarkedCompleteMissingOnReadFileBoltDB(t *testing.T) {
36         testMarkedCompleteMissingOnRead(t, NewBoltDB)
37 }