github.com/docker/docker@v299999999.0.0-20200612211812-aaf470eca7b5+incompatible/integration/internal/requirement/requirement.go (about)

     1  package requirement // import "github.com/docker/docker/integration/internal/requirement"
     2  
     3  import (
     4  	"net/http"
     5  	"strings"
     6  	"testing"
     7  	"time"
     8  )
     9  
    10  // HasHubConnectivity checks to see if https://hub.docker.com is
    11  // accessible from the present environment
    12  func HasHubConnectivity(t *testing.T) bool {
    13  	t.Helper()
    14  	// Set a timeout on the GET at 15s
    15  	var timeout = 15 * time.Second
    16  	var url = "https://hub.docker.com"
    17  
    18  	client := http.Client{Timeout: timeout}
    19  	resp, err := client.Get(url)
    20  	if err != nil && strings.Contains(err.Error(), "use of closed network connection") {
    21  		t.Fatalf("Timeout for GET request on %s", url)
    22  	}
    23  	if resp != nil {
    24  		resp.Body.Close()
    25  	}
    26  	return err == nil
    27  }