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

Commit

Permalink
test: add unit test case for func ParsePieceIndex
Browse files Browse the repository at this point in the history
Signed-off-by: Guangwen Feng <[email protected]>
  • Loading branch information
Guangwen Feng committed Jan 4, 2020
1 parent 48a4736 commit 3d768bb
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 3d768bb

Please sign in to comment.