forked from ovh/terraform-provider-ovh
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprovider_test.go
194 lines (156 loc) · 4.93 KB
/
provider_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
package ovh
import (
"fmt"
"log"
"os"
"testing"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/terraform"
"github.com/ovh/go-ovh/ovh"
)
var testAccProviders map[string]terraform.ResourceProvider
var testAccProvider *schema.Provider
var testAccOVHClient *ovh.Client
func init() {
log.SetOutput(os.Stdout)
testAccProvider = Provider().(*schema.Provider)
testAccProviders = map[string]terraform.ResourceProvider{
"ovh": testAccProvider,
}
}
func TestProvider(t *testing.T) {
if err := Provider().(*schema.Provider).InternalValidate(); err != nil {
t.Fatalf("err: %s", err)
}
}
func TestProvider_impl(t *testing.T) {
var _ terraform.ResourceProvider = Provider()
}
func checkEnvOrFail(t *testing.T, e string) {
if os.Getenv(e) == "" {
t.Fatalf("%s must be set for acceptance tests", e)
}
}
func checkEnvOrSkip(t *testing.T, e string) {
if os.Getenv(e) == "" {
t.Skipf("[WARN] %s must be set for acceptance tests. Skipping.", e)
}
}
// Checks that the environment variables needed to create the OVH API client
// are set and create the client right away.
func testAccPreCheckCredentials(t *testing.T) {
checkEnvOrFail(t, "OVH_ENDPOINT")
checkEnvOrFail(t, "OVH_APPLICATION_KEY")
checkEnvOrFail(t, "OVH_APPLICATION_SECRET")
checkEnvOrFail(t, "OVH_CONSUMER_KEY")
if testAccOVHClient == nil {
config := Config{
Endpoint: os.Getenv("OVH_ENDPOINT"),
ApplicationKey: os.Getenv("OVH_APPLICATION_KEY"),
ApplicationSecret: os.Getenv("OVH_APPLICATION_SECRET"),
ConsumerKey: os.Getenv("OVH_CONSUMER_KEY"),
}
if err := config.loadAndValidate(); err != nil {
t.Fatalf("Couldn't load OVH Client: %s", err)
} else {
testAccOVHClient = config.OVHClient
}
}
}
// Checks that the environment variables needed for the /ip acceptance tests
// are set.
func testAccPreCheckIp(t *testing.T) {
testAccPreCheckCredentials(t)
checkEnvOrSkip(t, "OVH_IP")
checkEnvOrSkip(t, "OVH_IP_BLOCK")
checkEnvOrSkip(t, "OVH_IP_REVERSE")
}
// Checks that the environment variables needed for the /domain acceptance tests
// are set.
func testAccPreCheckDomain(t *testing.T) {
testAccPreCheckCredentials(t)
checkEnvOrSkip(t, "OVH_ZONE")
}
// Checks that the environment variables needed for the /cloud acceptance tests
// are set.
func testAccPreCheckCloud(t *testing.T) {
testAccPreCheckCredentials(t)
checkEnvOrSkip(t, "OVH_PUBLIC_CLOUD")
}
// Checks that the environment variables needed for the /ipLoadbalacing acceptance tests
// are set.
func testAccPreCheckIpLoadbalancing(t *testing.T) {
testAccPreCheckCredentials(t)
checkEnvOrSkip(t, "OVH_IPLB_SERVICE")
}
// Checks that the environment variables needed for the /vrack acceptance tests
// are set.
func testAccPreCheckVRack(t *testing.T) {
testAccPreCheckCredentials(t)
checkEnvOrSkip(t, "OVH_VRACK")
}
// Checks that the environment variables needed for the /me/paymentMean acceptance tests
// are set.
func testAccPreCheckMePaymentMean(t *testing.T) {
testAccPreCheckCredentials(t)
checkEnvOrSkip(t, "OVH_TEST_BANKACCOUNT")
}
func testAccPreCheckDedicatedServer(t *testing.T) {
testAccPreCheckCredentials(t)
checkEnvOrSkip(t, "OVH_DEDICATED_SERVER")
}
func testAccPreCheckVPS(t *testing.T) {
testAccPreCheckCredentials(t)
checkEnvOrSkip(t, "OVH_VPS")
}
func testAccCheckVRackExists(t *testing.T) {
type vrackResponse struct {
Name string `json:"name"`
Description string `json:"description"`
}
r := vrackResponse{}
endpoint := fmt.Sprintf("/vrack/%s", os.Getenv("OVH_VRACK"))
err := testAccOVHClient.Get(endpoint, &r)
if err != nil {
t.Fatalf("Error: %q\n", err)
}
}
func testAccCheckCloudExists(t *testing.T) {
type cloudProjectResponse struct {
ID string `json:"project_id"`
Status string `json:"status"`
Description string `json:"description"`
}
r := cloudProjectResponse{}
endpoint := fmt.Sprintf("/cloud/project/%s", os.Getenv("OVH_PUBLIC_CLOUD"))
err := testAccOVHClient.Get(endpoint, &r)
if err != nil {
t.Fatalf("Error: %q\n", err)
}
t.Logf("Read Cloud Project %s -> status: '%s', desc: '%s'", endpoint, r.Status, r.Description)
}
func testAccCheckIpLoadbalancingExists(t *testing.T) {
type iplbResponse struct {
ServiceName string `json:"serviceName"`
State string `json:"state"`
}
r := iplbResponse{}
endpoint := fmt.Sprintf("/ipLoadbalancing/%s", os.Getenv("OVH_IPLB_SERVICE"))
err := testAccOVHClient.Get(endpoint, &r)
if err != nil {
t.Fatalf("Error: %q\n", err)
}
t.Logf("Read IPLB service %s -> state: '%s', serviceName: '%s'", endpoint, r.State, r.ServiceName)
}
func testAccCheckDomainZoneExists(t *testing.T) {
type domainZoneResponse struct {
NameServers []string `json:"nameServers"`
}
r := domainZoneResponse{}
endpoint := fmt.Sprintf("/domain/zone/%s", os.Getenv("OVH_ZONE"))
err := testAccOVHClient.Get(endpoint, &r)
if err != nil {
t.Fatalf("Error: %q\n", err)
}
t.Logf("Read Domain Zone %s -> nameservers: '%v'", endpoint, r.NameServers)
}