mirror of
https://github.com/pgsty/minio.git
synced 2026-03-16 01:26:03 +01:00
config: Accept more address format + unit test (#3915)
checkURL() is a generic function to check if a passed address is valid. This commit adds support for addresses like `m1` and `172.16.3.1` which is needed in MySQL and NATS. This commit also adds tests.
This commit is contained in:
committed by
Harshavardhana
parent
f3334159a4
commit
8426cf9aec
@@ -388,3 +388,30 @@ func TestLocalAddress(t *testing.T) {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// TestCheckURL tests valid address
|
||||
func TestCheckURL(t *testing.T) {
|
||||
testCases := []struct {
|
||||
addr string
|
||||
shouldPass bool
|
||||
}{
|
||||
{"", false},
|
||||
{":", false},
|
||||
{"localhost", true},
|
||||
{"127.0.0.1", true},
|
||||
{"http://localhost/", true},
|
||||
{"http://127.0.0.1/", true},
|
||||
{"proto://myhostname/path", true},
|
||||
}
|
||||
|
||||
// Validates fetching local address.
|
||||
for i, testCase := range testCases {
|
||||
_, err := checkURL(testCase.addr)
|
||||
if testCase.shouldPass && err != nil {
|
||||
t.Errorf("Test %d: expected to pass but got an error: %v\n", i+1, err)
|
||||
}
|
||||
if !testCase.shouldPass && err == nil {
|
||||
t.Errorf("Test %d: expected to fail but passed.", i+1)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user