github.com/demonoid81/moby@v0.0.0-20200517203328-62dd8e17c460/integration/internal/requirement/requirement.go (about)

     1  package requirement // import "github.com/demonoid81/moby/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  }