fix: Better printing of XL config init error (#5284)

This commit is contained in:
A. Elleuch
2017-12-28 18:32:48 +01:00
committed by Nitish Tiwari
parent e3d841ffd1
commit 2244adff07
16 changed files with 151 additions and 61 deletions

View File

@@ -18,6 +18,7 @@ package cmd
import (
"encoding/json"
"errors"
"net/http"
"net/url"
"reflect"
@@ -312,3 +313,38 @@ func TestToS3ETag(t *testing.T) {
}
}
}
// Test contains
func TestContains(t *testing.T) {
testErr := errors.New("test err")
testCases := []struct {
slice interface{}
elem interface{}
found bool
}{
{nil, nil, false},
{"1", "1", false},
{nil, "1", false},
{[]string{"1"}, nil, false},
{[]string{}, "1", false},
{[]string{"1"}, "1", true},
{[]string{"2"}, "1", false},
{[]string{"1", "2"}, "1", true},
{[]string{"2", "1"}, "1", true},
{[]string{"2", "1", "3"}, "1", true},
{[]int{1, 2, 3}, "1", false},
{[]int{1, 2, 3}, 2, true},
{[]int{1, 2, 3, 4, 5, 6}, 7, false},
{[]error{errors.New("new err")}, testErr, false},
{[]error{errors.New("new err"), testErr}, testErr, true},
}
for i, testCase := range testCases {
found := contains(testCase.slice, testCase.elem)
if found != testCase.found {
t.Fatalf("Test %v: expected: %v, got: %v", i+1, testCase.found, found)
}
}
}