fix bug of host.Extract (#1481)

pull/1488/head
letian 3 years ago committed by GitHub
parent 24ec23f0e4
commit 2ce8f22fac
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      internal/host/host.go
  2. 7
      internal/host/host_test.go

@ -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 {

@ -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) {

Loading…
Cancel
Save