mirror of
https://github.com/gohugoio/hugo.git
synced 2025-04-26 13:40:38 +03:00
commands: Improve server startup to make tests less flaky
Do this by announcing/listen on the local address before we start the server.
This commit is contained in:
parent
0e305d6958
commit
9539069f5e
5 changed files with 84 additions and 55 deletions
|
@ -62,6 +62,21 @@ func FindAvailablePort() (*net.TCPAddr, error) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
// TCPListen starts listening on a valid TCP port.
|
||||
func TCPListen() (net.Listener, *net.TCPAddr, error) {
|
||||
l, err := net.Listen("tcp", ":0")
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
addr := l.Addr()
|
||||
if a, ok := addr.(*net.TCPAddr); ok {
|
||||
return l, a, nil
|
||||
}
|
||||
l.Close()
|
||||
return nil, nil, fmt.Errorf("unable to obtain a valid tcp port: %v", addr)
|
||||
|
||||
}
|
||||
|
||||
// InStringArray checks if a string is an element of a slice of strings
|
||||
// and returns a boolean value.
|
||||
func InStringArray(arr []string, el string) bool {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue