]> Sergey Matveev's repositories - btrtrc.git/blob - storage/file-misc_test.go
Remove torrentfs-macos job from CI
[btrtrc.git] / storage / file-misc_test.go
1 package storage
2
3 import (
4         "testing"
5
6         "github.com/stretchr/testify/assert"
7
8         "github.com/anacrolix/torrent/metainfo"
9 )
10
11 func TestExtentCompleteRequiredLengths(t *testing.T) {
12         info := &metainfo.Info{
13                 Files: []metainfo.FileInfo{
14                         {Path: []string{"a"}, Length: 2},
15                         {Path: []string{"b"}, Length: 3},
16                 },
17         }
18         assert.Empty(t, extentCompleteRequiredLengths(info, 0, 0))
19         assert.EqualValues(t, []requiredLength{
20                 {fileIndex: 0, length: 1},
21         }, extentCompleteRequiredLengths(info, 0, 1))
22         assert.EqualValues(t, []requiredLength{
23                 {fileIndex: 0, length: 2},
24         }, extentCompleteRequiredLengths(info, 0, 2))
25         assert.EqualValues(t, []requiredLength{
26                 {fileIndex: 0, length: 2},
27                 {fileIndex: 1, length: 1},
28         }, extentCompleteRequiredLengths(info, 0, 3))
29         assert.EqualValues(t, []requiredLength{
30                 {fileIndex: 1, length: 2},
31         }, extentCompleteRequiredLengths(info, 2, 2))
32         assert.EqualValues(t, []requiredLength{
33                 {fileIndex: 1, length: 3},
34         }, extentCompleteRequiredLengths(info, 4, 1))
35         assert.Len(t, extentCompleteRequiredLengths(info, 5, 0), 0)
36         assert.Panics(t, func() { extentCompleteRequiredLengths(info, 6, 1) })
37 }