-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.go
42 lines (33 loc) · 783 Bytes
/
utils.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package envtest
import (
"fmt"
"net/http"
"time"
"github.com/docker/go-connections/nat"
)
// Helper function to wait for the cluster to become healthy.
func waitForCluster(url string, retries int, interval time.Duration) bool {
var counter int
for {
counter++
res, err := http.Get(url)
if err == nil && res.StatusCode == http.StatusOK {
return true
}
if counter >= retries {
return false
}
time.Sleep(interval)
}
}
// Helper function to lookup the port mapped for a container.
func getContainerPort(ports nat.PortMap, port nat.Port) (string, error) {
for key, bindings := range ports {
if key == port {
for _, binding := range bindings {
return binding.HostPort, nil
}
}
}
return "", fmt.Errorf("failed to find port: %s", port)
}