Skip to content

Commit e66b129

Browse files
authored
Merge pull request #106 from yanndegat/dev/skiptestaccontc
testing: skip acc tests if required env var not present
2 parents 0efde59 + 0ccacec commit e66b129

File tree

2 files changed

+20
-15
lines changed

2 files changed

+20
-15
lines changed

ovh/provider_test.go

+19-15
Original file line numberDiff line numberDiff line change
@@ -34,19 +34,25 @@ func TestProvider_impl(t *testing.T) {
3434
var _ terraform.ResourceProvider = Provider()
3535
}
3636

37-
func checkEnv(t *testing.T, e string) {
37+
func checkEnvOrFail(t *testing.T, e string) {
3838
if os.Getenv(e) == "" {
3939
t.Fatalf("%s must be set for acceptance tests", e)
4040
}
4141
}
4242

43+
func checkEnvOrSkip(t *testing.T, e string) {
44+
if os.Getenv(e) == "" {
45+
t.Skipf("[WARN] %s must be set for acceptance tests. Skipping.", e)
46+
}
47+
}
48+
4349
// Checks that the environment variables needed to create the OVH API client
4450
// are set and create the client right away.
4551
func testAccPreCheckCredentials(t *testing.T) {
46-
checkEnv(t, "OVH_ENDPOINT")
47-
checkEnv(t, "OVH_APPLICATION_KEY")
48-
checkEnv(t, "OVH_APPLICATION_SECRET")
49-
checkEnv(t, "OVH_CONSUMER_KEY")
52+
checkEnvOrFail(t, "OVH_ENDPOINT")
53+
checkEnvOrFail(t, "OVH_APPLICATION_KEY")
54+
checkEnvOrFail(t, "OVH_APPLICATION_SECRET")
55+
checkEnvOrFail(t, "OVH_CONSUMER_KEY")
5056

5157
if testAccOVHClient == nil {
5258
config := Config{
@@ -68,44 +74,44 @@ func testAccPreCheckCredentials(t *testing.T) {
6874
// are set.
6975
func testAccPreCheckIp(t *testing.T) {
7076
testAccPreCheckCredentials(t)
71-
checkEnv(t, "OVH_IP")
72-
checkEnv(t, "OVH_IP_BLOCK")
73-
checkEnv(t, "OVH_IP_REVERSE")
77+
checkEnvOrSkip(t, "OVH_IP")
78+
checkEnvOrSkip(t, "OVH_IP_BLOCK")
79+
checkEnvOrSkip(t, "OVH_IP_REVERSE")
7480
}
7581

7682
// Checks that the environment variables needed for the /domain acceptance tests
7783
// are set.
7884
func testAccPreCheckDomain(t *testing.T) {
7985
testAccPreCheckCredentials(t)
80-
checkEnv(t, "OVH_ZONE")
86+
checkEnvOrSkip(t, "OVH_ZONE")
8187
}
8288

8389
// Checks that the environment variables needed for the /cloud acceptance tests
8490
// are set.
8591
func testAccPreCheckPublicCloud(t *testing.T) {
8692
testAccPreCheckCredentials(t)
87-
checkEnv(t, "OVH_PUBLIC_CLOUD")
93+
checkEnvOrSkip(t, "OVH_PUBLIC_CLOUD")
8894
}
8995

9096
// Checks that the environment variables needed for the /ipLoadbalacing acceptance tests
9197
// are set.
9298
func testAccPreCheckIpLoadbalancing(t *testing.T) {
9399
testAccPreCheckCredentials(t)
94-
checkEnv(t, "OVH_IPLB_SERVICE")
100+
checkEnvOrSkip(t, "OVH_IPLB_SERVICE")
95101
}
96102

97103
// Checks that the environment variables needed for the /vrack acceptance tests
98104
// are set.
99105
func testAccPreCheckVRack(t *testing.T) {
100106
testAccPreCheckCredentials(t)
101-
checkEnv(t, "OVH_VRACK")
107+
checkEnvOrSkip(t, "OVH_VRACK")
102108
}
103109

104110
// Checks that the environment variables needed for the /me/paymentMean acceptance tests
105111
// are set.
106112
func testAccPreCheckMePaymentMean(t *testing.T) {
107113
testAccPreCheckCredentials(t)
108-
checkEnv(t, "OVH_TEST_BANKACCOUNT")
114+
checkEnvOrSkip(t, "OVH_TEST_BANKACCOUNT")
109115
}
110116

111117
func testAccCheckVRackExists(t *testing.T) {
@@ -142,7 +148,6 @@ func testAccCheckPublicCloudExists(t *testing.T) {
142148
t.Fatalf("Error: %q\n", err)
143149
}
144150
t.Logf("Read Cloud Project %s -> status: '%s', desc: '%s'", endpoint, r.Status, r.Description)
145-
146151
}
147152

148153
func testAccCheckIpLoadbalancingExists(t *testing.T) {
@@ -160,7 +165,6 @@ func testAccCheckIpLoadbalancingExists(t *testing.T) {
160165
t.Fatalf("Error: %q\n", err)
161166
}
162167
t.Logf("Read IPLB service %s -> state: '%s', serviceName: '%s'", endpoint, r.State, r.ServiceName)
163-
164168
}
165169

166170
func testAccCheckDomainZoneExists(t *testing.T) {

ovh/resource_ovh_iploadbalancing_tcp_farm_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ func testAccIpLoadbalancingTcpFarmTestStep(name, zone string, port, probePort, p
7979
func TestAccIpLoadbalancingTcpFarmBasicCreate(t *testing.T) {
8080
resource.Test(t, resource.TestCase{
8181
Providers: testAccProviders,
82+
PreCheck: func() { testAccPreCheckIpLoadbalancing(t) },
8283
CheckDestroy: testAccCheckIpLoadbalancingTcpFarmDestroy,
8384
Steps: []resource.TestStep{
8485
testAccIpLoadbalancingTcpFarmTestStep("test-farm-v1", "all", 8080, 8888, 35, "tcp"),

0 commit comments

Comments
 (0)