github.com/cmalfait/terraform@v0.11.12-beta1/helper/acctest/remotetests.go (about)

     1  package acctest
     2  
     3  import (
     4  	"net/http"
     5  	"os"
     6  	"testing"
     7  )
     8  
     9  // SkipRemoteTestsEnvVar is an environment variable that can be set by a user
    10  // running the tests in an environment with limited network connectivity. By
    11  // default, tests requiring internet connectivity make an effort to skip if no
    12  // internet is available, but in some cases the smoke test will pass even
    13  // though the test should still be skipped.
    14  const SkipRemoteTestsEnvVar = "TF_SKIP_REMOTE_TESTS"
    15  
    16  // RemoteTestPrecheck is meant to be run by any unit test that requires
    17  // outbound internet connectivity. The test will be skipped if it's
    18  // unavailable.
    19  func RemoteTestPrecheck(t *testing.T) {
    20  	if os.Getenv(SkipRemoteTestsEnvVar) != "" {
    21  		t.Skipf("skipping test, %s was set", SkipRemoteTestsEnvVar)
    22  	}
    23  
    24  	if _, err := http.Get("http://google.com"); err != nil {
    25  		t.Skipf("skipping, internet seems to not be available: %s", err)
    26  	}
    27  }