integration randomPort() returns an unallocated port
@@ -21,6 +21,7 @@ import (
"fmt"
"io/ioutil"
"math/rand"
+ "net"
"net/http"
"strconv"
"strings"
@@ -353,11 +354,19 @@ func setupSkaffoldWithArgs(t *testing.T, args ...string) {
})
}
-// randomPort chooses a port in range [1024, 65535]
+// randomPort chooses a random port
func randomPort() string {
+ l, err := net.Listen("tcp", "localhost:0")
+ if err != nil {
+ // listening for port 0 should never error but just in case
return strconv.Itoa(1024 + rand.Intn(65536-1024))
}
+ p := l.Addr().(*net.TCPAddr).Port
+ l.Close()
+ return strconv.Itoa(p)
+}
+
func checkBuildAndDeployComplete(state proto.State) bool {
if state.BuildState == nil || state.DeployState == nil {
return false
