xl/utils: getPartSizeFromIdx should return error. (#3669)

This commit is contained in:
Harshavardhana
2017-01-31 15:34:49 -08:00
committed by GitHub
parent f7f103725b
commit 1b30a3be2b
3 changed files with 56 additions and 11 deletions
+26 -2
View File
@@ -353,9 +353,33 @@ func TestGetPartSizeFromIdx(t *testing.T) {
}
for i, testCase := range testCases {
s := getPartSizeFromIdx(testCase.totalSize, testCase.partSize, testCase.partIndex)
if s != testCase.expectedSize {
s, err := getPartSizeFromIdx(testCase.totalSize, testCase.partSize, testCase.partIndex)
if err != nil {
t.Errorf("Test %d: Expected to pass but failed. %s", i+1, err)
}
if err == nil && s != testCase.expectedSize {
t.Errorf("Test %d: The calculated part size is incorrect: expected = %d, found = %d\n", i+1, testCase.expectedSize, s)
}
}
testCasesFailure := []struct {
totalSize int64
partSize int64
partIndex int
err error
}{
// partSize is 0, error.
{10, 0, 1, errPartSizeZero},
{10, 1, 0, errPartSizeIndex},
}
for i, testCaseFailure := range testCasesFailure {
_, err := getPartSizeFromIdx(testCaseFailure.totalSize, testCaseFailure.partSize, testCaseFailure.partIndex)
if err == nil {
t.Errorf("Test %d: Expected to failed but passed. %s", i+1, err)
}
if err != nil && errorCause(err) != testCaseFailure.err {
t.Errorf("Test %d: Expected err %s, but got %s", i+1, testCaseFailure.err, errorCause(err))
}
}
}