2018-02-09 13:13:26 -05:00
|
|
|
package requirement // import "github.com/docker/docker/integration/internal/requirement"
|
2017-09-22 09:05:56 -04:00
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
"strings"
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
|
|
|
// HasHubConnectivity checks to see if https://hub.docker.com is
|
|
|
|
// accessible from the present environment
|
2017-10-02 17:02:52 -04:00
|
|
|
func HasHubConnectivity(t *testing.T) bool {
|
2018-04-18 11:16:55 -04:00
|
|
|
t.Helper()
|
2017-09-22 09:05:56 -04:00
|
|
|
// Set a timeout on the GET at 15s
|
|
|
|
var timeout = 15 * time.Second
|
|
|
|
var url = "https://hub.docker.com"
|
|
|
|
|
2017-10-02 17:02:52 -04:00
|
|
|
client := http.Client{Timeout: timeout}
|
2017-09-22 09:05:56 -04:00
|
|
|
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()
|
|
|
|
}
|
2017-10-02 17:02:52 -04:00
|
|
|
return err == nil
|
2017-09-22 09:05:56 -04:00
|
|
|
}
|