Skip to content
This repository has been archived by the owner on Feb 27, 2023. It is now read-only.

Commit

Permalink
Merge pull request #1160 from fenggw-fnst/work
Browse files Browse the repository at this point in the history
test: add unit test case for func ParsePieceIndex
  • Loading branch information
starnop committed Jan 5, 2020
2 parents 48a4736 + 3d768bb commit 7894da1
Showing 1 changed file with 55 additions and 0 deletions.
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

0 comments on commit 7894da1

Please sign in to comment.