update test cases (!!!)

This commit is contained in:
maycxc.github.io 2024-10-12 18:57:11 -04:00
parent 110b58a255
commit de85a8ba3d
2 changed files with 11 additions and 6 deletions

View File

@ -390,10 +390,13 @@ func SplitNetworkAddress(a string) (network, host, port string, err error) {
firstErr := err
if err != nil {
a = strings.TrimPrefix(a, "[") // IPv6
a = strings.TrimSuffix(a, "]")
// in general, if there was an error, it was likely "missing port",
// so try adding a bogus port to take advantage of standard library's
// robust parser.
// robust parser, then strip the artificial port.
host, _, err = net.SplitHostPort(net.JoinHostPort(a, "0"))
port = ""
}
if err != nil {

View File

@ -31,7 +31,7 @@ func TestSplitNetworkAddress(t *testing.T) {
}{
{
input: "",
expectErr: true,
expectHost: "",
},
{
input: "foo",
@ -42,7 +42,7 @@ func TestSplitNetworkAddress(t *testing.T) {
},
{
input: "::",
expectErr: true,
expectHost: "::",
},
{
input: "[::]",
@ -77,7 +77,7 @@ func TestSplitNetworkAddress(t *testing.T) {
{
input: "udp/",
expectNetwork: "udp",
expectErr: true,
expectHost: "",
},
{
input: "unix//foo/bar",
@ -185,7 +185,8 @@ func TestParseNetworkAddress(t *testing.T) {
}{
{
input: "",
expectErr: true,
expectAddr: NetworkAddress{
},
},
{
input: ":",
@ -311,7 +312,8 @@ func TestParseNetworkAddressWithDefaults(t *testing.T) {
}{
{
input: "",
expectErr: true,
expectAddr: NetworkAddress{
},
},
{
input: ":",