requirement.go 604 B

1234567891011121314151617181920212223242526
  1. package 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. // Set a timeout on the GET at 15s
  12. var timeout = 15 * time.Second
  13. var url = "https://hub.docker.com"
  14. client := http.Client{Timeout: timeout}
  15. resp, err := client.Get(url)
  16. if err != nil && strings.Contains(err.Error(), "use of closed network connection") {
  17. t.Fatalf("Timeout for GET request on %s", url)
  18. }
  19. if resp != nil {
  20. resp.Body.Close()
  21. }
  22. return err == nil
  23. }