opentofu/helper/acctest/remotetests.go
Paul Hinze 6bafa74011 tests: allow opt-out of remote tests via env var
Adds the `TF_SKIP_REMOTE_TESTS` env var to be used in cases where the
`http.Get()` smoke test passes but the network is not able to service
the needs of the tests.

Fixes #4421
2016-01-21 15:44:18 -06:00

28 lines
901 B
Go

package acctest
import (
"net/http"
"os"
"testing"
)
// SkipRemoteTestsEnvVar is an environment variable that can be set by a user
// running the tests in an environment with limited network connectivity. By
// default, tests requiring internet connectivity make an effort to skip if no
// internet is available, but in some cases the smoke test will pass even
// though the test should still be skipped.
const SkipRemoteTestsEnvVar = "TF_SKIP_REMOTE_TESTS"
// RemoteTestPrecheck is meant to be run by any unit test that requires
// outbound internet connectivity. The test will be skipped if it's
// unavailable.
func RemoteTestPrecheck(t *testing.T) {
if os.Getenv(SkipRemoteTestsEnvVar) != "" {
t.Skipf("skipping test, %s was set", SkipRemoteTestsEnvVar)
}
if _, err := http.Get("http://google.com"); err != nil {
t.Skipf("skipping, internet seems to not be available: %s", err)
}
}