2016-10-05 15:48:07 -04:00
|
|
|
/*
|
2017-01-18 15:24:34 -05:00
|
|
|
* Minio Cloud Storage, (C) 2016, 2017 Minio, Inc.
|
2016-10-05 15:48:07 -04:00
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
package cmd
|
|
|
|
|
2016-11-02 11:51:06 -04:00
|
|
|
import (
|
|
|
|
"net/url"
|
2016-11-09 13:50:14 -05:00
|
|
|
"reflect"
|
2016-11-02 11:51:06 -04:00
|
|
|
"testing"
|
|
|
|
)
|
2016-10-05 15:48:07 -04:00
|
|
|
|
2016-11-09 13:50:14 -05:00
|
|
|
// Tests and validates the output for heal endpoint.
|
|
|
|
func TestGetHealEndpoint(t *testing.T) {
|
|
|
|
// Test for a SSL scheme.
|
|
|
|
tls := true
|
|
|
|
hURL := getHealEndpoint(tls, &url.URL{
|
2017-01-18 15:24:34 -05:00
|
|
|
Scheme: httpScheme,
|
2016-11-09 13:50:14 -05:00
|
|
|
Host: "localhost:9000",
|
|
|
|
})
|
|
|
|
sHURL := &url.URL{
|
2017-01-18 15:24:34 -05:00
|
|
|
Scheme: httpsScheme,
|
2016-11-09 13:50:14 -05:00
|
|
|
Host: "localhost:9000",
|
|
|
|
}
|
|
|
|
if !reflect.DeepEqual(hURL, sHURL) {
|
|
|
|
t.Fatalf("Expected %#v, but got %#v", sHURL, hURL)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Test a non-TLS scheme.
|
|
|
|
tls = false
|
|
|
|
hURL = getHealEndpoint(tls, &url.URL{
|
2017-01-18 15:24:34 -05:00
|
|
|
Scheme: httpsScheme,
|
2016-11-09 13:50:14 -05:00
|
|
|
Host: "localhost:9000",
|
|
|
|
})
|
|
|
|
sHURL = &url.URL{
|
2017-01-18 15:24:34 -05:00
|
|
|
Scheme: httpScheme,
|
2016-11-09 13:50:14 -05:00
|
|
|
Host: "localhost:9000",
|
|
|
|
}
|
|
|
|
if !reflect.DeepEqual(hURL, sHURL) {
|
|
|
|
t.Fatalf("Expected %#v, but got %#v", sHURL, hURL)
|
|
|
|
}
|
|
|
|
|
|
|
|
// FIXME(GLOBAL): purposefully Host is left empty because
|
|
|
|
// we need to bring in safe handling on global values
|
|
|
|
// add a proper test case here once that happens.
|
|
|
|
/*
|
|
|
|
tls = false
|
|
|
|
hURL = getHealEndpoint(tls, &url.URL{
|
|
|
|
Path: "/export",
|
|
|
|
})
|
|
|
|
sHURL = &url.URL{
|
2017-01-18 15:24:34 -05:00
|
|
|
Scheme: httpScheme,
|
2016-11-09 13:50:14 -05:00
|
|
|
Host: "",
|
|
|
|
}
|
|
|
|
globalMinioAddr = ""
|
|
|
|
if !reflect.DeepEqual(hURL, sHURL) {
|
|
|
|
t.Fatalf("Expected %#v, but got %#v", sHURL, hURL)
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
}
|
|
|
|
|
2016-10-05 15:48:07 -04:00
|
|
|
// Tests heal message to be correct and properly formatted.
|
|
|
|
func TestHealMsg(t *testing.T) {
|
2017-01-18 15:24:34 -05:00
|
|
|
rootPath, err := newTestConfig(globalMinioDefaultRegion)
|
2016-10-07 14:15:55 -04:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal("Unable to initialize test config", err)
|
|
|
|
}
|
|
|
|
defer removeAll(rootPath)
|
2016-10-05 15:48:07 -04:00
|
|
|
storageDisks, fsDirs := prepareXLStorageDisks(t)
|
2016-10-07 14:15:55 -04:00
|
|
|
errs := make([]error, len(storageDisks))
|
2016-10-05 15:48:07 -04:00
|
|
|
defer removeRoots(fsDirs)
|
2016-10-07 14:15:55 -04:00
|
|
|
nilDisks := deepCopyStorageDisks(storageDisks)
|
|
|
|
nilDisks[5] = nil
|
|
|
|
authErrs := make([]error, len(storageDisks))
|
|
|
|
authErrs[5] = errAuthentication
|
2016-11-02 11:51:06 -04:00
|
|
|
endpointURL, err := url.Parse("http://10.1.10.1:9000")
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal("Unexpected error:", err)
|
|
|
|
}
|
|
|
|
endpointURLs := make([]*url.URL, len(storageDisks))
|
|
|
|
for idx := 0; idx < len(endpointURLs); idx++ {
|
|
|
|
endpointURLs[idx] = endpointURL
|
|
|
|
}
|
|
|
|
|
2016-10-05 15:48:07 -04:00
|
|
|
testCases := []struct {
|
2016-11-02 11:51:06 -04:00
|
|
|
endPoints []*url.URL
|
2016-10-05 15:48:07 -04:00
|
|
|
storageDisks []StorageAPI
|
2016-10-07 14:15:55 -04:00
|
|
|
serrs []error
|
2016-10-05 15:48:07 -04:00
|
|
|
}{
|
2016-10-07 14:15:55 -04:00
|
|
|
// Test - 1 for valid disks and errors.
|
2016-10-05 15:48:07 -04:00
|
|
|
{
|
2016-11-02 11:51:06 -04:00
|
|
|
endPoints: endpointURLs,
|
2016-10-05 15:48:07 -04:00
|
|
|
storageDisks: storageDisks,
|
2016-10-07 14:15:55 -04:00
|
|
|
serrs: errs,
|
|
|
|
},
|
|
|
|
// Test - 2 for one of the disks is nil.
|
|
|
|
{
|
2016-11-02 11:51:06 -04:00
|
|
|
endPoints: endpointURLs,
|
2016-10-07 14:15:55 -04:00
|
|
|
storageDisks: nilDisks,
|
|
|
|
serrs: errs,
|
|
|
|
},
|
|
|
|
// Test - 3 for one of the errs is authentication.
|
|
|
|
{
|
2016-11-02 11:51:06 -04:00
|
|
|
endPoints: endpointURLs,
|
2016-10-07 14:15:55 -04:00
|
|
|
storageDisks: nilDisks,
|
|
|
|
serrs: authErrs,
|
2016-10-05 15:48:07 -04:00
|
|
|
},
|
|
|
|
}
|
|
|
|
for i, testCase := range testCases {
|
2016-11-09 13:50:14 -05:00
|
|
|
msg := getHealMsg(testCase.endPoints, testCase.storageDisks)
|
2016-10-05 15:48:07 -04:00
|
|
|
if msg == "" {
|
|
|
|
t.Fatalf("Test: %d Unable to get heal message.", i+1)
|
|
|
|
}
|
2016-11-02 11:51:06 -04:00
|
|
|
msg = getStorageInitMsg("init", testCase.endPoints, testCase.storageDisks)
|
2016-10-05 15:48:07 -04:00
|
|
|
if msg == "" {
|
|
|
|
t.Fatalf("Test: %d Unable to get regular message.", i+1)
|
|
|
|
}
|
2016-10-07 14:15:55 -04:00
|
|
|
msg = getConfigErrMsg(testCase.storageDisks, testCase.serrs)
|
|
|
|
if msg == "" {
|
|
|
|
t.Fatalf("Test: %d Unable to get config error message.", i+1)
|
|
|
|
}
|
2016-10-05 15:48:07 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Tests disk info, validates if we do return proper disk info structure
|
|
|
|
// even in case of certain disks not available.
|
|
|
|
func TestDisksInfo(t *testing.T) {
|
|
|
|
storageDisks, fsDirs := prepareXLStorageDisks(t)
|
|
|
|
defer removeRoots(fsDirs)
|
|
|
|
|
|
|
|
testCases := []struct {
|
|
|
|
storageDisks []StorageAPI
|
|
|
|
onlineDisks int
|
|
|
|
offlineDisks int
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
storageDisks: storageDisks,
|
|
|
|
onlineDisks: 16,
|
|
|
|
offlineDisks: 0,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
storageDisks: prepareNOfflineDisks(deepCopyStorageDisks(storageDisks), 4, t),
|
|
|
|
onlineDisks: 12,
|
|
|
|
offlineDisks: 4,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
storageDisks: prepareNOfflineDisks(deepCopyStorageDisks(storageDisks), 16, t),
|
|
|
|
onlineDisks: 0,
|
|
|
|
offlineDisks: 16,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for i, testCase := range testCases {
|
|
|
|
_, onlineDisks, offlineDisks := getDisksInfo(testCase.storageDisks)
|
|
|
|
if testCase.onlineDisks != onlineDisks {
|
|
|
|
t.Errorf("Test %d: Expected online disks %d, got %d", i+1, testCase.onlineDisks, onlineDisks)
|
|
|
|
}
|
|
|
|
if testCase.offlineDisks != offlineDisks {
|
|
|
|
t.Errorf("Test %d: Expected offline disks %d, got %d", i+1, testCase.offlineDisks, offlineDisks)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|