Util: Modify SplitHostPortDefault not to return an error for empty input (#20351)

* Util: Optionally allow empty input in SplitHostPortDefault

Due to a recent change the SQL Server tests failed because passing an
empty datasource url in `util.SplitHostPortDefault` was no more allowed.
This fix contains the following modifications:
- Modifies the util.SplitHostPortDefault not to return an error for empty input.
- Modifies the util.SplitHostPort to return an error for empty input.
- Introduces an additional test for empty input.
This commit is contained in:
Sofia Papagiannaki 2019-11-18 10:42:51 +02:00 committed by GitHub
parent eadf324062
commit 886bad2fd5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 1 deletions

View File

@ -44,7 +44,7 @@ func SplitHostPortDefault(input, defaultHost, defaultPort string) (NetworkAddres
Port: defaultPort,
}
if len(input) == 0 {
return addr, fmt.Errorf("Input is empty")
return addr, nil
}
start := 0
@ -82,5 +82,8 @@ func SplitHostPortDefault(input, defaultHost, defaultPort string) (NetworkAddres
// SplitHostPort splits ip address/hostname string by host and port
func SplitHostPort(input string) (NetworkAddress, error) {
if len(input) == 0 {
return NetworkAddress{}, fmt.Errorf("Input is empty")
}
return SplitHostPortDefault(input, "", "")
}

View File

@ -87,6 +87,11 @@ func TestSplitHostPortDefault(t *testing.T) {
So(err, ShouldBeNil)
So(addr.Host, ShouldEqual, "xyz.rds.amazonaws.com")
So(addr.Port, ShouldEqual, "123")
addr, err = SplitHostPortDefault("", "localhost", "1433")
So(err, ShouldBeNil)
So(addr.Host, ShouldEqual, "localhost")
So(addr.Port, ShouldEqual, "1433")
})
}