Skip to content

Commit

Permalink
fix bug of host.Extract (#1481)
Browse files Browse the repository at this point in the history
  • Loading branch information
letian0805 committed Sep 15, 2021
1 parent 24ec23f commit 2ce8f22
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion internal/host/host.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func Port(lis net.Listener) (int, bool) {
// Extract returns a private addr and port.
func Extract(hostPort string, lis net.Listener) (string, error) {
addr, port, err := net.SplitHostPort(hostPort)
if err != nil {
if err != nil && lis == nil {
return "", err
}
if lis != nil {
Expand Down
7 changes: 7 additions & 0 deletions internal/host/host_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,13 @@ func TestExtract(t *testing.T) {
}
})
}
lis, err := net.Listen("tcp", ":12345")
assert.NoError(t, err)
res, err := Extract("", lis)
assert.NoError(t, err)
expect, err := Extract(lis.Addr().String(), nil)
assert.NoError(t, err)
assert.Equal(t, expect, res)
}

func TestExtract2(t *testing.T) {
Expand Down

0 comments on commit 2ce8f22

Please sign in to comment.