2016-07-10 21:03:59 +08:00
|
|
|
package storage
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
|
|
|
|
"github.com/anacrolix/torrent/metainfo"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestExtentCompleteRequiredLengths(t *testing.T) {
|
2016-08-26 18:29:05 +08:00
|
|
|
info := &metainfo.Info{
|
|
|
|
Files: []metainfo.FileInfo{
|
|
|
|
{Path: []string{"a"}, Length: 2},
|
|
|
|
{Path: []string{"b"}, Length: 3},
|
2016-07-10 21:03:59 +08:00
|
|
|
},
|
|
|
|
}
|
2016-08-26 18:29:05 +08:00
|
|
|
assert.Empty(t, extentCompleteRequiredLengths(info, 0, 0))
|
2016-07-10 21:03:59 +08:00
|
|
|
assert.EqualValues(t, []metainfo.FileInfo{
|
|
|
|
{Path: []string{"a"}, Length: 1},
|
2016-08-26 18:29:05 +08:00
|
|
|
}, extentCompleteRequiredLengths(info, 0, 1))
|
2016-07-10 21:03:59 +08:00
|
|
|
assert.EqualValues(t, []metainfo.FileInfo{
|
|
|
|
{Path: []string{"a"}, Length: 2},
|
2016-08-26 18:29:05 +08:00
|
|
|
}, extentCompleteRequiredLengths(info, 0, 2))
|
2016-07-10 21:03:59 +08:00
|
|
|
assert.EqualValues(t, []metainfo.FileInfo{
|
|
|
|
{Path: []string{"a"}, Length: 2},
|
|
|
|
{Path: []string{"b"}, Length: 1},
|
2016-08-26 18:29:05 +08:00
|
|
|
}, extentCompleteRequiredLengths(info, 0, 3))
|
2016-07-10 21:03:59 +08:00
|
|
|
assert.EqualValues(t, []metainfo.FileInfo{
|
|
|
|
{Path: []string{"b"}, Length: 2},
|
2016-08-26 18:29:05 +08:00
|
|
|
}, extentCompleteRequiredLengths(info, 2, 2))
|
2016-07-10 21:03:59 +08:00
|
|
|
assert.EqualValues(t, []metainfo.FileInfo{
|
|
|
|
{Path: []string{"b"}, Length: 3},
|
2016-08-26 18:29:05 +08:00
|
|
|
}, extentCompleteRequiredLengths(info, 4, 1))
|
|
|
|
assert.Len(t, extentCompleteRequiredLengths(info, 5, 0), 0)
|
|
|
|
assert.Panics(t, func() { extentCompleteRequiredLengths(info, 6, 1) })
|
2016-07-10 21:03:59 +08:00
|
|
|
}
|