From 3d768bb157e0b9fee6d2cceb85c230ea90ccbbcf Mon Sep 17 00:00:00 2001 From: Guangwen Feng Date: Sat, 4 Jan 2020 19:48:24 +0800 Subject: [PATCH] test: add unit test case for func ParsePieceIndex Signed-off-by: Guangwen Feng --- supernode/util/range_util_test.go | 55 +++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/supernode/util/range_util_test.go b/supernode/util/range_util_test.go index 059238df8..7fbcaaaef 100644 --- a/supernode/util/range_util_test.go +++ b/supernode/util/range_util_test.go @@ -19,6 +19,8 @@ package util import ( "testing" + "github.com/dragonflyoss/Dragonfly/pkg/util" + "github.com/go-check/check" ) @@ -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