File tree Expand file tree Collapse file tree
website/source/docs/configuration Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff line change 99 "testing"
1010 "time"
1111
12+ "github.com/hashicorp/terraform/helper/acctest"
1213 "github.com/hashicorp/terraform/terraform"
1314)
1415
@@ -17,9 +18,7 @@ func TestAtlasClient_impl(t *testing.T) {
1718}
1819
1920func TestAtlasClient (t * testing.T ) {
20- if _ , err := http .Get ("http://google.com" ); err != nil {
21- t .Skipf ("skipping, internet seems to not be available: %s" , err )
22- }
21+ acctest .RemoteTestPrecheck (t )
2322
2423 token := os .Getenv ("ATLAS_TOKEN" )
2524 if token == "" {
Original file line number Diff line number Diff line change @@ -2,19 +2,18 @@ package remote
22
33import (
44 "fmt"
5- "net/http"
65 "testing"
76 "time"
7+
8+ "github.com/hashicorp/terraform/helper/acctest"
89)
910
1011func TestConsulClient_impl (t * testing.T ) {
1112 var _ Client = new (ConsulClient )
1213}
1314
1415func TestConsulClient (t * testing.T ) {
15- if _ , err := http .Get ("http://google.com" ); err != nil {
16- t .Skipf ("skipping, internet seems to not be available: %s" , err )
17- }
16+ acctest .RemoteTestPrecheck (t )
1817
1918 client , err := consulFactory (map [string ]string {
2019 "address" : "demo.consul.io:80" ,
Original file line number Diff line number Diff line change @@ -62,3 +62,15 @@ export TF_VAR_ami=ami-049d8641
6262```
6363
6464For more on how to use ` TF_VAR_name ` in context, check out the section on [ Variable Configuration] ( /docs/configuration/variables.html ) .
65+
66+ ## TF_SKIP_REMOTE_TESTS
67+
68+ This can be set prior to running the unit tests to opt-out of any tests
69+ requiring remote network connectivity. The unit tests make an attempt to
70+ automatically detect when connectivity is unavailable and skip the relevant
71+ tests, but by setting this variable you can force these tests to be skipped.
72+
73+ ```
74+ export TF_SKIP_REMOTE_TESTS=1
75+ make test
76+ ```
You can’t perform that action at this time.
0 commit comments