github.com/opentofu/opentofu@v1.7.1/internal/legacy/helper/acctest/remotetests.go (about)

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