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.
pull/20441/head
Sofia Papagiannaki 6 years ago committed by GitHub
parent eadf324062
commit 886bad2fd5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 5
      pkg/util/ip_address.go
  2. 5
      pkg/util/ip_address_test.go

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

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

Loading…
Cancel
Save