github.com/terramate-io/tf@v0.0.0-20230830114523-fce866b4dfcd/legacy/helper/acctest/remotetests.go (about)

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