requirement.go 680 B

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