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:
Anis Elleuch
2017-03-16 19:44:01 +01:00
committed by Harshavardhana
parent f3334159a4
commit 8426cf9aec
8 changed files with 39 additions and 12 deletions

View File

@@ -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)
}
}
}