Skip to content
This repository has been archived by the owner on Dec 20, 2024. It is now read-only.

test: add unit test case for func ParsePieceIndex #1160

Merged
merged 1 commit into from
Jan 5, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 55 additions & 0 deletions supernode/util/range_util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ package util
import (
"testing"

"github.com/dragonflyoss/Dragonfly/pkg/util"

"github.com/go-check/check"
)

Expand Down Expand Up @@ -114,6 +116,59 @@ func (suite *RangeUtilSuite) TestCalculatePieceNum(c *check.C) {
}
}

func (suite *RangeUtilSuite) TestParsePieceIndex(c *check.C) {
var cases = []struct {
rangeStr string
expectedStart int64
expectedEnd int64
errNil bool
}{
{
rangeStr: "2-3",
expectedStart: 2,
expectedEnd: 3,
errNil: true,
},
{
rangeStr: "2-2",
expectedStart: 2,
expectedEnd: 2,
errNil: true,
},
{
rangeStr: "2-3-3",
expectedStart: -1,
expectedEnd: -1,
errNil: false,
},
{
rangeStr: "2 -3",
expectedStart: -1,
expectedEnd: -1,
errNil: false,
},
{
rangeStr: "2- 3",
expectedStart: -1,
expectedEnd: -1,
errNil: false,
},
{
rangeStr: "3-2",
expectedStart: -1,
expectedEnd: -1,
errNil: false,
},
}

for _, v := range cases {
start, end, err := ParsePieceIndex(v.rangeStr)
c.Assert(start, check.Equals, v.expectedStart)
c.Assert(end, check.Equals, v.expectedEnd)
c.Assert(util.IsNil(err), check.Equals, v.errNil)
}
}

func (suite *RangeUtilSuite) TestCalculateBreakRange(c *check.C) {
var cases = []struct {
startPieceNum int
Expand Down