Merge pull request #4788 from hashicorp/phinze/skip-remote-test-option
tests: allow opt-out of remote tests via env var
This commit is contained in:
commit
0b11ace9ac
|
@ -0,0 +1,27 @@
|
||||||
|
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)
|
||||||
|
}
|
||||||
|
}
|
|
@ -9,6 +9,7 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/hashicorp/terraform/helper/acctest"
|
||||||
"github.com/hashicorp/terraform/terraform"
|
"github.com/hashicorp/terraform/terraform"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -17,9 +18,7 @@ func TestAtlasClient_impl(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestAtlasClient(t *testing.T) {
|
func TestAtlasClient(t *testing.T) {
|
||||||
if _, err := http.Get("http://google.com"); err != nil {
|
acctest.RemoteTestPrecheck(t)
|
||||||
t.Skipf("skipping, internet seems to not be available: %s", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
token := os.Getenv("ATLAS_TOKEN")
|
token := os.Getenv("ATLAS_TOKEN")
|
||||||
if token == "" {
|
if token == "" {
|
||||||
|
|
|
@ -2,9 +2,10 @@ package remote
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/hashicorp/terraform/helper/acctest"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestConsulClient_impl(t *testing.T) {
|
func TestConsulClient_impl(t *testing.T) {
|
||||||
|
@ -12,9 +13,7 @@ func TestConsulClient_impl(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestConsulClient(t *testing.T) {
|
func TestConsulClient(t *testing.T) {
|
||||||
if _, err := http.Get("http://google.com"); err != nil {
|
acctest.RemoteTestPrecheck(t)
|
||||||
t.Skipf("skipping, internet seems to not be available: %s", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
client, err := consulFactory(map[string]string{
|
client, err := consulFactory(map[string]string{
|
||||||
"address": "demo.consul.io:80",
|
"address": "demo.consul.io:80",
|
||||||
|
|
|
@ -62,3 +62,15 @@ export TF_VAR_ami=ami-049d8641
|
||||||
```
|
```
|
||||||
|
|
||||||
For more on how to use `TF_VAR_name` in context, check out the section on [Variable Configuration](/docs/configuration/variables.html).
|
For more on how to use `TF_VAR_name` in context, check out the section on [Variable Configuration](/docs/configuration/variables.html).
|
||||||
|
|
||||||
|
## TF_SKIP_REMOTE_TESTS
|
||||||
|
|
||||||
|
This can be set prior to running the unit tests to opt-out of any tests
|
||||||
|
requiring remote network connectivity. The unit tests make an attempt to
|
||||||
|
automatically detect when connectivity is unavailable and skip the relevant
|
||||||
|
tests, but by setting this variable you can force these tests to be skipped.
|
||||||
|
|
||||||
|
```
|
||||||
|
export TF_SKIP_REMOTE_TESTS=1
|
||||||
|
make test
|
||||||
|
```
|
||||||
|
|
Loading…
Reference in New Issue