Skip to content

Commit 0d1263b

Browse files
authored
Merge pull request #94 from pgaxatte/split-pre-check
Split PreCheck for acceptance tests
2 parents 378309b + e0fd7c9 commit 0d1263b

21 files changed

+82
-84
lines changed

go.sum

+2
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9
116116
github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY=
117117
github.com/go-test/deep v1.0.1 h1:UQhStjbkDClarlmv0am7OXXO4/GaPdCGiUiMTvi28sg=
118118
github.com/go-test/deep v1.0.1/go.mod h1:wGDj63lr65AM2AQyKZd/NYHGb0R+1RLqB8NKt3aSFNA=
119+
github.com/go-test/deep v1.0.3 h1:ZrJSEWsXzPOxaZnFteGEfooLba+ju3FYIbOrS+rQd68=
119120
github.com/go-test/deep v1.0.3/go.mod h1:wGDj63lr65AM2AQyKZd/NYHGb0R+1RLqB8NKt3aSFNA=
120121
github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ=
121122
github.com/gogo/protobuf v1.2.0 h1:xU6/SpYbvkNYiptHJYEDRseDLvYE7wSqhYYNy0QSUzI=
@@ -127,6 +128,7 @@ github.com/golang/lint v0.0.0-20180702182130-06c8688daad7/go.mod h1:tluoj9z5200j
127128
github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A=
128129
github.com/golang/mock v1.2.0 h1:28o5sBqPkBsMGnC6b4MvE2TzSr5/AT4c/1fLqVGIwlk=
129130
github.com/golang/mock v1.2.0/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A=
131+
github.com/golang/mock v1.3.1 h1:qGJ6qTW+x6xX/my+8YUVl4WNpX9B7+/l2tRsHGZ7f2s=
130132
github.com/golang/mock v1.3.1/go.mod h1:sBzyDLLjw3U8JLTeZvSv8jJB+tU5PVekmnlKIyFUx0Y=
131133
github.com/golang/protobuf v1.1.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
132134
github.com/golang/protobuf v1.2.0 h1:P3YflyNX/ehuJFLhxviNdFxQPkGK5cDcApsge1SqnvM=

ovh/data_source_ovh_domain_zone_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ func TestAccDomainZoneDataSource_basic(t *testing.T) {
1515
config := fmt.Sprintf(testAccDomainZoneDatasourceConfig_Basic, zoneName)
1616

1717
resource.Test(t, resource.TestCase{
18-
PreCheck: func() { testAccPreCheck(t); testAccCheckDomainZoneExists(t) },
18+
PreCheck: func() { testAccPreCheckDomain(t); testAccCheckDomainZoneExists(t) },
1919
Providers: testAccProviders,
2020
Steps: []resource.TestStep{
2121
{

ovh/data_source_ovh_iploadbalancing_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ func TestAccIpLoadbalancingDataSource_basic(t *testing.T) {
1313
config := fmt.Sprintf(testAccIpLoadbalancingDatasourceConfig_Basic, serviceName)
1414

1515
resource.Test(t, resource.TestCase{
16-
PreCheck: func() { testAccPreCheck(t) },
16+
PreCheck: func() { testAccPreCheckIpLoadbalancing(t) },
1717
Providers: testAccProviders,
1818
Steps: []resource.TestStep{
1919
{
@@ -34,7 +34,7 @@ func TestAccIpLoadbalancingDataSource_statevrack(t *testing.T) {
3434
config := fmt.Sprintf(testAccIpLoadbalancingDatasourceConfig_StateAndVrack, serviceName)
3535

3636
resource.Test(t, resource.TestCase{
37-
PreCheck: func() { testAccPreCheck(t) },
37+
PreCheck: func() { testAccPreCheckIpLoadbalancing(t) },
3838
Providers: testAccProviders,
3939
Steps: []resource.TestStep{
4040
{

ovh/data_source_ovh_me_paymentmean_bankaccount_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ func TestAccMePaymentmeanBankaccountDataSource_basic(t *testing.T) {
1414
v := os.Getenv("OVH_TEST_BANKACCOUNT")
1515
if v == "1" {
1616
resource.Test(t, resource.TestCase{
17-
PreCheck: func() { testAccPreCheck(t) },
17+
PreCheck: func() { testAccPreCheckMePaymentMean(t) },
1818
Providers: testAccProviders,
1919
Steps: []resource.TestStep{
2020
{

ovh/data_source_ovh_me_paymentmean_creditcard_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ func TestAccMePaymentmeanCreditcardDataSource_basic(t *testing.T) {
1414
v := os.Getenv("OVH_TEST_CREDITCARD")
1515
if v == "1" {
1616
resource.Test(t, resource.TestCase{
17-
PreCheck: func() { testAccPreCheck(t) },
17+
PreCheck: func() { testAccPreCheckMePaymentMean(t) },
1818
Providers: testAccProviders,
1919
Steps: []resource.TestStep{
2020
{

ovh/data_source_ovh_publiccloud_region_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111

1212
func TestAccPublicCloudRegionDataSource_basic(t *testing.T) {
1313
resource.Test(t, resource.TestCase{
14-
PreCheck: func() { testAccPreCheck(t) },
14+
PreCheck: func() { testAccPreCheckPublicCloud(t) },
1515
Providers: testAccProviders,
1616
Steps: []resource.TestStep{
1717
{

ovh/data_source_ovh_publiccloud_regions_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111

1212
func TestAccPublicCloudRegionsDataSource_basic(t *testing.T) {
1313
resource.Test(t, resource.TestCase{
14-
PreCheck: func() { testAccPreCheck(t) },
14+
PreCheck: func() { testAccPreCheckPublicCloud(t) },
1515
Providers: testAccProviders,
1616
Steps: []resource.TestStep{
1717
{

ovh/provider_test.go

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

37-
func testAccPreCheck(t *testing.T) {
38-
v := os.Getenv("OVH_ENDPOINT")
39-
if v == "" {
40-
t.Fatal("OVH_ENDPOINT must be set for acceptance tests")
41-
}
42-
43-
v = os.Getenv("OVH_APPLICATION_KEY")
44-
if v == "" {
45-
t.Fatal("OVH_APPLICATION_KEY must be set for acceptance tests")
46-
}
47-
48-
v = os.Getenv("OVH_APPLICATION_SECRET")
49-
if v == "" {
50-
t.Fatal("OVH_APPLICATION_SECRET must be set for acceptance tests")
51-
}
52-
53-
v = os.Getenv("OVH_CONSUMER_KEY")
54-
if v == "" {
55-
t.Fatal("OVH_CONSUMER_KEY must be set for acceptance tests")
56-
}
57-
58-
v = os.Getenv("OVH_VRACK")
59-
if v == "" {
60-
t.Fatal("OVH_VRACK must be set for acceptance tests")
61-
}
62-
63-
v = os.Getenv("OVH_PUBLIC_CLOUD")
64-
if v == "" {
65-
t.Fatal("OVH_PUBLIC_CLOUD must be set for acceptance tests")
66-
}
67-
68-
v = os.Getenv("OVH_ZONE")
69-
if v == "" {
70-
t.Fatal("OVH_ZONE must be set for acceptance tests")
71-
}
72-
73-
v = os.Getenv("OVH_IPLB_SERVICE")
74-
if v == "" {
75-
t.Fatal("OVH_IPLB_SERVICE must be set for acceptance tests")
76-
}
77-
78-
v = os.Getenv("OVH_IP_BLOCK")
79-
if v == "" {
80-
t.Fatal("OVH_IP_BLOCK must be set for acceptance tests")
81-
}
82-
83-
v = os.Getenv("OVH_IP")
84-
if v == "" {
85-
t.Fatal("OVH_IP must be set for acceptance tests")
37+
func checkEnv(t *testing.T, e string) {
38+
if os.Getenv(e) == "" {
39+
t.Fatalf("%s must be set for acceptance tests", e)
8640
}
41+
}
8742

88-
v = os.Getenv("OVH_IP_REVERSE")
89-
if v == "" {
90-
t.Fatal("OVH_IP_REVERSE must be set for acceptance tests")
91-
}
43+
// Checks that the environment variables needed to create the OVH API client
44+
// are set and create the client right away.
45+
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")
9250

9351
if testAccOVHClient == nil {
9452
config := Config{
@@ -99,13 +57,57 @@ func testAccPreCheck(t *testing.T) {
9957
}
10058

10159
if err := config.loadAndValidate(); err != nil {
102-
t.Fatalf("couln't load OVH Client: %s", err)
60+
t.Fatalf("Couldn't load OVH Client: %s", err)
10361
} else {
10462
testAccOVHClient = config.OVHClient
10563
}
10664
}
10765
}
10866

67+
// Checks that the environment variables needed for the /ip acceptance tests
68+
// are set.
69+
func testAccPreCheckIp(t *testing.T) {
70+
testAccPreCheckCredentials(t)
71+
checkEnv(t, "OVH_IP")
72+
checkEnv(t, "OVH_IP_BLOCK")
73+
checkEnv(t, "OVH_IP_REVERSE")
74+
}
75+
76+
// Checks that the environment variables needed for the /domain acceptance tests
77+
// are set.
78+
func testAccPreCheckDomain(t *testing.T) {
79+
testAccPreCheckCredentials(t)
80+
checkEnv(t, "OVH_ZONE")
81+
}
82+
83+
// Checks that the environment variables needed for the /cloud acceptance tests
84+
// are set.
85+
func testAccPreCheckPublicCloud(t *testing.T) {
86+
testAccPreCheckCredentials(t)
87+
checkEnv(t, "OVH_PUBLIC_CLOUD")
88+
}
89+
90+
// Checks that the environment variables needed for the /ipLoadbalacing acceptance tests
91+
// are set.
92+
func testAccPreCheckIpLoadbalancing(t *testing.T) {
93+
testAccPreCheckCredentials(t)
94+
checkEnv(t, "OVH_IPLB_SERVICE")
95+
}
96+
97+
// Checks that the environment variables needed for the /vrack acceptance tests
98+
// are set.
99+
func testAccPreCheckVRack(t *testing.T) {
100+
testAccPreCheckCredentials(t)
101+
checkEnv(t, "OVH_VRACK")
102+
}
103+
104+
// Checks that the environment variables needed for the /me/paymentMean acceptance tests
105+
// are set.
106+
func testAccPreCheckMePaymentMean(t *testing.T) {
107+
testAccPreCheckCredentials(t)
108+
checkEnv(t, "OVH_TEST_BANKACCOUNT")
109+
}
110+
109111
func testAccCheckVRackExists(t *testing.T) {
110112
type vrackResponse struct {
111113
Name string `json:"name"`

ovh/resource_ovh_domain_zone_record_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ func TestAccOvhDomainZoneRecord_Basic(t *testing.T) {
9898
subdomain := acctest.RandomWithPrefix(test_prefix)
9999

100100
resource.Test(t, resource.TestCase{
101-
PreCheck: func() { testAccPreCheck(t) },
101+
PreCheck: func() { testAccPreCheckDomain(t) },
102102
Providers: testAccProviders,
103103
CheckDestroy: testAccCheckOvhDomainZoneRecordDestroy,
104104
Steps: []resource.TestStep{
@@ -126,7 +126,7 @@ func TestAccOvhDomainZoneRecord_Updated(t *testing.T) {
126126
subdomain := acctest.RandomWithPrefix(test_prefix)
127127

128128
resource.Test(t, resource.TestCase{
129-
PreCheck: func() { testAccPreCheck(t) },
129+
PreCheck: func() { testAccPreCheckDomain(t) },
130130
Providers: testAccProviders,
131131
CheckDestroy: testAccCheckOvhDomainZoneRecordDestroy,
132132
Steps: []resource.TestStep{
@@ -198,7 +198,7 @@ func TestAccOvhDomainZoneRecord_updateType(t *testing.T) {
198198
subdomain := acctest.RandomWithPrefix(test_prefix)
199199

200200
resource.Test(t, resource.TestCase{
201-
PreCheck: func() { testAccPreCheck(t) },
201+
PreCheck: func() { testAccPreCheckDomain(t) },
202202
Providers: testAccProviders,
203203
CheckDestroy: testAccCheckOvhDomainZoneRecordDestroy,
204204
Steps: []resource.TestStep{

ovh/resource_ovh_domain_zone_redirection_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ func TestAccOvhDomainZoneRedirection_Basic(t *testing.T) {
9494
subdomain := acctest.RandomWithPrefix(test_prefix)
9595

9696
resource.Test(t, resource.TestCase{
97-
PreCheck: func() { testAccPreCheck(t) },
97+
PreCheck: func() { testAccPreCheckDomain(t) },
9898
Providers: testAccProviders,
9999
CheckDestroy: testAccCheckOvhDomainZoneRedirectionDestroy,
100100
Steps: []resource.TestStep{
@@ -122,7 +122,7 @@ func TestAccOvhDomainZoneRedirection_Updated(t *testing.T) {
122122
subdomain := acctest.RandomWithPrefix(test_prefix)
123123

124124
resource.Test(t, resource.TestCase{
125-
PreCheck: func() { testAccPreCheck(t) },
125+
PreCheck: func() { testAccPreCheckDomain(t) },
126126
Providers: testAccProviders,
127127
CheckDestroy: testAccCheckOvhDomainZoneRedirectionDestroy,
128128
Steps: []resource.TestStep{

ovh/resource_ovh_ip_reverse_test.go

+1-5
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,9 @@ resource "ovh_ip_reverse" "reverse" {
1717
}
1818
`, os.Getenv("OVH_IP_BLOCK"), os.Getenv("OVH_IP"), os.Getenv("OVH_IP_REVERSE"))
1919

20-
func testAccCheckIpReversePreCheck(t *testing.T) {
21-
testAccPreCheck(t)
22-
}
23-
2420
func TestAccIpReverse_basic(t *testing.T) {
2521
resource.Test(t, resource.TestCase{
26-
PreCheck: func() { testAccCheckIpReversePreCheck(t) },
22+
PreCheck: func() { testAccPreCheckIp(t) },
2723
Providers: testAccProviders,
2824
CheckDestroy: testAccCheckIpReverseDestroy,
2925
Steps: []resource.TestStep{

ovh/resource_ovh_iploadbalancing_http_farm_server_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,7 @@ func TestAccIpLoadbalancingHttpFarmServerBasicCreate(t *testing.T) {
237237
steps = append(steps, w.TestStep(tcase))
238238
}
239239
resource.Test(t, resource.TestCase{
240+
PreCheck: func() { testAccPreCheckIpLoadbalancing(t) },
240241
Providers: testAccProviders,
241242
CheckDestroy: w.TestDestroy,
242243
Steps: steps,

ovh/resource_ovh_iploadbalancing_http_farm_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ func testAccIpLoadbalancingHttpFarmTestStep(name, zone string, port, probePort,
7878

7979
func TestAccIpLoadbalancingHttpFarmBasicCreate(t *testing.T) {
8080
resource.Test(t, resource.TestCase{
81+
PreCheck: func() { testAccPreCheckIpLoadbalancing(t) },
8182
Providers: testAccProviders,
8283
CheckDestroy: testAccCheckIpLoadbalancingHttpFarmDestroy,
8384
Steps: []resource.TestStep{

ovh/resource_ovh_iploadbalancing_http_route_rule_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ func TestAccIPLoadbalancingRouteHTTPRuleBasicCreate(t *testing.T) {
6262
}
6363

6464
func testAccCheckIpLoadbalancingRouteHTTPRulePreCheck(t *testing.T) {
65-
testAccPreCheck(t)
65+
testAccPreCheckIpLoadbalancing(t)
6666
testAccCheckIpLoadbalancingExists(t)
6767
}
6868

ovh/resource_ovh_iploadbalancing_http_route_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ func TestAccIPLoadbalancingRouteHTTPBasicCreate(t *testing.T) {
5757
}
5858

5959
func testAccCheckIpLoadbalancingRouteHTTPPreCheck(t *testing.T) {
60-
testAccPreCheck(t)
60+
testAccPreCheckIpLoadbalancing(t)
6161
testAccCheckIpLoadbalancingExists(t)
6262
}
6363

ovh/resource_ovh_iploadbalancing_tcp_farm_server_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,7 @@ func TestAccIpLoadbalancingTcpFarmServerBasicCreate(t *testing.T) {
237237
steps = append(steps, w.TestStep(tcase))
238238
}
239239
resource.Test(t, resource.TestCase{
240+
PreCheck: func() { testAccPreCheckIpLoadbalancing(t) },
240241
Providers: testAccProviders,
241242
CheckDestroy: w.TestDestroy,
242243
Steps: steps,

ovh/resource_ovh_iploadbalancing_tcp_frontend_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ func TestAccOvhIpLoadbalancingTcpFrontend_basic(t *testing.T) {
6969
iplb := os.Getenv("OVH_IPLB_SERVICE")
7070

7171
resource.Test(t, resource.TestCase{
72-
PreCheck: func() { testAccPreCheck(t) },
72+
PreCheck: func() { testAccPreCheckIpLoadbalancing(t) },
7373
Providers: testAccProviders,
7474
Steps: []resource.TestStep{
7575
{
@@ -110,7 +110,7 @@ func TestAccOvhIpLoadbalancingTcpFrontend_withfarm(t *testing.T) {
110110
iplb := os.Getenv("OVH_IPLB_SERVICE")
111111

112112
resource.Test(t, resource.TestCase{
113-
PreCheck: func() { testAccPreCheck(t) },
113+
PreCheck: func() { testAccPreCheckIpLoadbalancing(t) },
114114
Providers: testAccProviders,
115115
Steps: []resource.TestStep{
116116
{

ovh/resource_ovh_publiccloud_private_network_subnet_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ func TestAccPublicCloudPrivateNetworkSubnet_basic(t *testing.T) {
5959
}
6060

6161
func testAccCheckPublicCloudPrivateNetworkSubnetPreCheck(t *testing.T) {
62-
testAccPreCheck(t)
62+
testAccPreCheckPublicCloud(t)
6363
testAccCheckPublicCloudExists(t)
6464
}
6565

ovh/resource_ovh_publiccloud_private_network_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ func TestAccPublicCloudPrivateNetwork_basic(t *testing.T) {
121121
}
122122

123123
func testAccCheckPublicCloudPrivateNetworkPreCheck(t *testing.T) {
124-
testAccPreCheck(t)
124+
testAccPreCheckPublicCloud(t)
125125
testAccCheckPublicCloudExists(t)
126126
}
127127

ovh/resource_ovh_publiccloud_user_test.go

+1-6
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ resource "ovh_publiccloud_user" "user" {
1818

1919
func TestAccPublicCloudUser_basic(t *testing.T) {
2020
resource.Test(t, resource.TestCase{
21-
PreCheck: func() { testAccCheckPublicCloudUserPreCheck(t) },
21+
PreCheck: func() { testAccPreCheckPublicCloud(t); testAccCheckPublicCloudExists(t) },
2222
Providers: testAccProviders,
2323
CheckDestroy: testAccCheckPublicCloudUserDestroy,
2424
Steps: []resource.TestStep{
@@ -33,11 +33,6 @@ func TestAccPublicCloudUser_basic(t *testing.T) {
3333
})
3434
}
3535

36-
func testAccCheckPublicCloudUserPreCheck(t *testing.T) {
37-
testAccPreCheck(t)
38-
testAccCheckPublicCloudExists(t)
39-
}
40-
4136
func testAccCheckPublicCloudUserExists(n string, t *testing.T) resource.TestCheckFunc {
4237
return func(s *terraform.State) error {
4338
config := testAccProvider.Meta().(*Config)

ovh/resource_ovh_vrack_publiccloud_attachment_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ func TestAccVRackPublicCloudAttachment_basic(t *testing.T) {
3333
}
3434

3535
func testAccCheckVRackPublicCloudAttachmentPreCheck(t *testing.T) {
36-
testAccPreCheck(t)
36+
testAccPreCheckVRack(t)
3737
testAccCheckVRackExists(t)
3838
testAccCheckPublicCloudExists(t)
3939
}

0 commit comments

Comments
 (0)