Add extensive endpoints validation (#4019)

This commit is contained in:
Bala FA
2017-04-12 04:14:27 +05:30
committed by Harshavardhana
parent 1b1b9e4801
commit de204a0a52
48 changed files with 1432 additions and 2269 deletions

View File

@@ -18,12 +18,9 @@ package cmd
import (
"encoding/json"
"fmt"
"net"
"net/http"
"net/url"
"reflect"
"runtime"
"strings"
"testing"
)
@@ -52,57 +49,6 @@ func TestCloneHeader(t *testing.T) {
}
}
// Tests check duplicates function.
func TestCheckDuplicates(t *testing.T) {
tests := []struct {
list []string
err error
shouldPass bool
}{
// Test 1 - for '/tmp/1' repeated twice.
{
list: []string{"/tmp/1", "/tmp/1", "/tmp/2", "/tmp/3"},
err: fmt.Errorf("Duplicate key: \"/tmp/1\" found of count: \"2\""),
shouldPass: false,
},
// Test 2 - for '/tmp/1' repeated thrice.
{
list: []string{"/tmp/1", "/tmp/1", "/tmp/1", "/tmp/3"},
err: fmt.Errorf("Duplicate key: \"/tmp/1\" found of count: \"3\""),
shouldPass: false,
},
// Test 3 - empty string.
{
list: []string{""},
err: errInvalidArgument,
shouldPass: false,
},
// Test 4 - empty string.
{
list: nil,
err: errInvalidArgument,
shouldPass: false,
},
// Test 5 - non repeated strings.
{
list: []string{"/tmp/1", "/tmp/2", "/tmp/3"},
err: nil,
shouldPass: true,
},
}
// Validate if function runs as expected.
for i, test := range tests {
err := checkDuplicateStrings(test.list)
if test.shouldPass && err != test.err {
t.Errorf("Test: %d, Expected %s got %s", i+1, test.err, err)
}
if !test.shouldPass && err.Error() != test.err.Error() {
t.Errorf("Test: %d, Expected %s got %s", i+1, test.err, err)
}
}
}
// Tests maximum object size.
func TestMaxObjectSize(t *testing.T) {
sizes := []struct {
@@ -275,122 +221,6 @@ func TestStartProfiler(t *testing.T) {
}
}
// Tests fetch local address.
func TestLocalAddress(t *testing.T) {
if runtime.GOOS == globalWindowsOSName {
return
}
currentIsDistXL := globalIsDistXL
defer func() {
globalIsDistXL = currentIsDistXL
}()
// need to set this to avoid stale values from other tests.
globalMinioPort = "9000"
globalMinioHost = ""
testCases := []struct {
isDistXL bool
srvCmdConfig serverCmdConfig
localAddr string
}{
// Test 1 - local address is found.
{
isDistXL: true,
srvCmdConfig: serverCmdConfig{
endpoints: []*url.URL{{
Scheme: httpScheme,
Host: "localhost:9000",
Path: "/mnt/disk1",
}, {
Scheme: httpScheme,
Host: "1.1.1.2:9000",
Path: "/mnt/disk2",
}, {
Scheme: httpScheme,
Host: "1.1.2.1:9000",
Path: "/mnt/disk3",
}, {
Scheme: httpScheme,
Host: "1.1.2.2:9000",
Path: "/mnt/disk4",
}},
},
localAddr: net.JoinHostPort("localhost", globalMinioPort),
},
// Test 2 - local address is everything.
{
isDistXL: false,
srvCmdConfig: serverCmdConfig{
serverAddr: net.JoinHostPort("", globalMinioPort),
endpoints: []*url.URL{{
Path: "/mnt/disk1",
}, {
Path: "/mnt/disk2",
}, {
Path: "/mnt/disk3",
}, {
Path: "/mnt/disk4",
}},
},
localAddr: net.JoinHostPort("", globalMinioPort),
},
// Test 3 - local address is not found.
{
isDistXL: true,
srvCmdConfig: serverCmdConfig{
endpoints: []*url.URL{{
Scheme: httpScheme,
Host: "1.1.1.1:9000",
Path: "/mnt/disk2",
}, {
Scheme: httpScheme,
Host: "1.1.1.2:9000",
Path: "/mnt/disk2",
}, {
Scheme: httpScheme,
Host: "1.1.2.1:9000",
Path: "/mnt/disk3",
}, {
Scheme: httpScheme,
Host: "1.1.2.2:9000",
Path: "/mnt/disk4",
}},
},
localAddr: "",
},
// Test 4 - in case of FS mode, with SSL, the host
// name is specified in the --address option on the
// server command line.
{
isDistXL: false,
srvCmdConfig: serverCmdConfig{
serverAddr: "play.minio.io:9000",
endpoints: []*url.URL{{
Path: "/mnt/disk1",
}, {
Path: "/mnt/disk2",
}, {
Path: "/mnt/disk3",
}, {
Path: "/mnt/disk4",
}},
},
localAddr: "play.minio.io:9000",
},
}
// Validates fetching local address.
for i, testCase := range testCases {
globalIsDistXL = testCase.isDistXL
localAddr := getLocalAddress(testCase.srvCmdConfig)
if localAddr != testCase.localAddr {
t.Fatalf("Test %d: Expected %s, got %s", i+1, testCase.localAddr, localAddr)
}
}
}
// TestCheckURL tests valid url.
func TestCheckURL(t *testing.T) {
testCases := []struct {