Handle localhost distributed setups properly (#8577)

Fixes an issue reported by @klauspost and @vadmeste

This PR also allows users to expand their clusters
from single node XL deployment to distributed mode.
This commit is contained in:
Harshavardhana
2019-11-26 11:42:10 -08:00
committed by GitHub
parent 78eb3b78bb
commit 5d65428b29
16 changed files with 189 additions and 187 deletions

View File

@@ -137,7 +137,7 @@ func TestHostUnmarshalJSON(t *testing.T) {
{[]byte(`"12play"`), &Host{"12play", 0, false}, false},
{[]byte(`"play-minio-io"`), &Host{"play-minio-io", 0, false}, false},
{[]byte(`"play--min.io"`), &Host{"play--min.io", 0, false}, false},
{[]byte(`":9000"`), nil, true},
{[]byte(`":9000"`), &Host{"", 9000, true}, false},
{[]byte(`"[fe80::8097:76eb:b397:e067%wlp2s0]"`), &Host{"fe80::8097:76eb:b397:e067%wlp2s0", 0, false}, false},
{[]byte(`"[fe80::8097:76eb:b397:e067]:9000"`), &Host{"fe80::8097:76eb:b397:e067", 9000, true}, false},
{[]byte(`"fe80::8097:76eb:b397:e067%wlp2s0"`), nil, true},
@@ -154,20 +154,23 @@ func TestHostUnmarshalJSON(t *testing.T) {
{[]byte(`":"`), nil, true},
}
for i, testCase := range testCases {
var host Host
err := host.UnmarshalJSON(testCase.data)
expectErr := (err != nil)
for _, testCase := range testCases {
testCase := testCase
t.Run("", func(t *testing.T) {
var host Host
err := host.UnmarshalJSON(testCase.data)
expectErr := (err != nil)
if expectErr != testCase.expectErr {
t.Fatalf("test %v: error: expected: %v, got: %v", i+1, testCase.expectErr, expectErr)
}
if !testCase.expectErr {
if !reflect.DeepEqual(&host, testCase.expectedHost) {
t.Fatalf("test %v: host: expected: %#v, got: %#v", i+1, testCase.expectedHost, host)
if expectErr != testCase.expectErr {
t.Errorf("error: expected: %v, got: %v", testCase.expectErr, expectErr)
}
}
if !testCase.expectErr {
if !reflect.DeepEqual(&host, testCase.expectedHost) {
t.Errorf("host: expected: %#v, got: %#v", testCase.expectedHost, host)
}
}
})
}
}
@@ -188,7 +191,7 @@ func TestParseHost(t *testing.T) {
{"12play", &Host{"12play", 0, false}, false},
{"play-minio-io", &Host{"play-minio-io", 0, false}, false},
{"play--min.io", &Host{"play--min.io", 0, false}, false},
{":9000", nil, true},
{":9000", &Host{"", 9000, true}, false},
{"play:", nil, true},
{"play::", nil, true},
{"play:90000", nil, true},
@@ -199,19 +202,22 @@ func TestParseHost(t *testing.T) {
{"", nil, true},
}
for i, testCase := range testCases {
host, err := ParseHost(testCase.s)
expectErr := (err != nil)
for _, testCase := range testCases {
testCase := testCase
t.Run("", func(t *testing.T) {
host, err := ParseHost(testCase.s)
expectErr := (err != nil)
if expectErr != testCase.expectErr {
t.Fatalf("test %v: error: expected: %v, got: %v", i+1, testCase.expectErr, expectErr)
}
if !testCase.expectErr {
if !reflect.DeepEqual(host, testCase.expectedHost) {
t.Fatalf("test %v: host: expected: %#v, got: %#v", i+1, testCase.expectedHost, host)
if expectErr != testCase.expectErr {
t.Errorf("error: expected: %v, got: %v", testCase.expectErr, expectErr)
}
}
if !testCase.expectErr {
if !reflect.DeepEqual(host, testCase.expectedHost) {
t.Errorf("host: expected: %#v, got: %#v", testCase.expectedHost, host)
}
}
})
}
}