-
Notifications
You must be signed in to change notification settings - Fork 91
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix host:port joining for ipv6 listen addresses
- Loading branch information
Showing
5 changed files
with
74 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
// This code is available on the terms of the project LICENSE.md file, | ||
// also available online at https://blueoakcouncil.org/license/1.0.0. | ||
|
||
package main | ||
|
||
import "testing" | ||
|
||
const ( | ||
defaultHost = "127.0.0.1" | ||
defaultPort = "17232" | ||
) | ||
|
||
func Test_normalizeNetworkAddress(t *testing.T) { | ||
tests := []struct { | ||
listen string | ||
want string | ||
wantErr bool | ||
}{ | ||
{ | ||
listen: "[::1]", | ||
want: "[::1]:17232", | ||
}, | ||
{ | ||
listen: "[::]:", | ||
want: "[::]:17232", | ||
}, | ||
{ | ||
listen: "", | ||
want: "127.0.0.1:17232", | ||
}, | ||
{ | ||
listen: "127.0.0.2", | ||
want: "127.0.0.2:17232", | ||
}, | ||
{ | ||
listen: ":7222", | ||
want: "127.0.0.1:7222", | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.listen, func(t *testing.T) { | ||
got, err := normalizeNetworkAddress(tt.listen, defaultHost, defaultPort) | ||
if (err != nil) != tt.wantErr { | ||
t.Errorf("normalizeNetworkAddress() error = %v, wantErr %v", err, tt.wantErr) | ||
return | ||
} | ||
if got != tt.want { | ||
t.Errorf("normalizeNetworkAddress() = %v, want %v", got, tt.want) | ||
} | ||
}) | ||
} | ||
} |