mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-17 21:01:26 +02: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:
@@ -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 {
|
||||
|
Reference in New Issue
Block a user