mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
104c1c6843
Also skip.IfCondition directly from the test, so that the skip message is correct Signed-off-by: Daniel Nephin <dnephin@docker.com>
26 lines
604 B
Go
26 lines
604 B
Go
package requirement
|
|
|
|
import (
|
|
"net/http"
|
|
"strings"
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
// HasHubConnectivity checks to see if https://hub.docker.com is
|
|
// accessible from the present environment
|
|
func HasHubConnectivity(t *testing.T) bool {
|
|
// Set a timeout on the GET at 15s
|
|
var timeout = 15 * time.Second
|
|
var url = "https://hub.docker.com"
|
|
|
|
client := http.Client{Timeout: timeout}
|
|
resp, err := client.Get(url)
|
|
if err != nil && strings.Contains(err.Error(), "use of closed network connection") {
|
|
t.Fatalf("Timeout for GET request on %s", url)
|
|
}
|
|
if resp != nil {
|
|
resp.Body.Close()
|
|
}
|
|
return err == nil
|
|
}
|