diff options
Diffstat (limited to 'statuscake')
-rw-r--r-- | statuscake/provider_test.go | 15 | ||||
-rw-r--r-- | statuscake/resource_statuscaketest.go | 49 | ||||
-rw-r--r-- | statuscake/resource_statuscaketest_test.go | 35 |
3 files changed, 47 insertions, 52 deletions
diff --git a/statuscake/provider_test.go b/statuscake/provider_test.go index 83045d0..81d5888 100644 --- a/statuscake/provider_test.go +++ b/statuscake/provider_test.go | |||
@@ -1,7 +1,9 @@ | |||
1 | package statuscake | 1 | package statuscake |
2 | 2 | ||
3 | import ( | 3 | import ( |
4 | "fmt" | ||
4 | "os" | 5 | "os" |
6 | "strconv" | ||
5 | "testing" | 7 | "testing" |
6 | 8 | ||
7 | "github.com/hashicorp/terraform/helper/schema" | 9 | "github.com/hashicorp/terraform/helper/schema" |
@@ -10,12 +12,25 @@ import ( | |||
10 | 12 | ||
11 | var testAccProviders map[string]terraform.ResourceProvider | 13 | var testAccProviders map[string]terraform.ResourceProvider |
12 | var testAccProvider *schema.Provider | 14 | var testAccProvider *schema.Provider |
15 | var testContactGroupId int | ||
13 | 16 | ||
14 | func init() { | 17 | func init() { |
15 | testAccProvider = Provider().(*schema.Provider) | 18 | testAccProvider = Provider().(*schema.Provider) |
16 | testAccProviders = map[string]terraform.ResourceProvider{ | 19 | testAccProviders = map[string]terraform.ResourceProvider{ |
17 | "statuscake": testAccProvider, | 20 | "statuscake": testAccProvider, |
18 | } | 21 | } |
22 | |||
23 | if v := os.Getenv("STATUSCAKE_TEST_CONTACT_GROUP_ID"); v == "" { | ||
24 | fmt.Println("STATUSCAKE_TEST_CONTACT_GROUP_ID must be set for acceptance tests") | ||
25 | os.Exit(1) | ||
26 | } else { | ||
27 | id, err := strconv.Atoi(v) | ||
28 | if err != nil { | ||
29 | fmt.Println("STATUSCAKE_TEST_CONTACT_GROUP_ID must be a valid int") | ||
30 | os.Exit(1) | ||
31 | } | ||
32 | testContactGroupId = id | ||
33 | } | ||
19 | } | 34 | } |
20 | 35 | ||
21 | func TestProvider(t *testing.T) { | 36 | func TestProvider(t *testing.T) { |
diff --git a/statuscake/resource_statuscaketest.go b/statuscake/resource_statuscaketest.go index 459c71a..d7d3f36 100644 --- a/statuscake/resource_statuscaketest.go +++ b/statuscake/resource_statuscaketest.go | |||
@@ -10,16 +10,24 @@ import ( | |||
10 | "github.com/hashicorp/terraform/helper/schema" | 10 | "github.com/hashicorp/terraform/helper/schema" |
11 | ) | 11 | ) |
12 | 12 | ||
13 | func castInterfaceToSliceStrings(in interface{}) []string { | 13 | func castSetToSliceStrings(configured []interface{}) []string { |
14 | input := in.([]interface{}) | 14 | res := make([]string, len(configured)) |
15 | res := make([]string, len(input)) | ||
16 | 15 | ||
17 | for i, element := range input { | 16 | for i, element := range configured { |
18 | res[i] = element.(string) | 17 | res[i] = element.(string) |
19 | } | 18 | } |
20 | return res | 19 | return res |
21 | } | 20 | } |
22 | 21 | ||
22 | // Special handling for node_locations since statuscake will return `[""]` for the empty case | ||
23 | func considerEmptyStringAsEmptyArray(in []string) []string { | ||
24 | if len(in) == 1 && in[0] == "" { | ||
25 | return []string{} | ||
26 | } else { | ||
27 | return in | ||
28 | } | ||
29 | } | ||
30 | |||
23 | func resourceStatusCakeTest() *schema.Resource { | 31 | func resourceStatusCakeTest() *schema.Resource { |
24 | return &schema.Resource{ | 32 | return &schema.Resource{ |
25 | Create: CreateTest, | 33 | Create: CreateTest, |
@@ -107,9 +115,10 @@ func resourceStatusCakeTest() *schema.Resource { | |||
107 | }, | 115 | }, |
108 | 116 | ||
109 | "node_locations": { | 117 | "node_locations": { |
110 | Type: schema.TypeList, | 118 | Type: schema.TypeSet, |
111 | Elem: &schema.Schema{Type: schema.TypeString}, | 119 | Elem: &schema.Schema{Type: schema.TypeString}, |
112 | Optional: true, | 120 | Optional: true, |
121 | Set: schema.HashString, | ||
113 | }, | 122 | }, |
114 | 123 | ||
115 | "ping_url": { | 124 | "ping_url": { |
@@ -123,8 +132,9 @@ func resourceStatusCakeTest() *schema.Resource { | |||
123 | }, | 132 | }, |
124 | 133 | ||
125 | "basic_pass": { | 134 | "basic_pass": { |
126 | Type: schema.TypeString, | 135 | Type: schema.TypeString, |
127 | Optional: true, | 136 | Optional: true, |
137 | Sensitive: true, | ||
128 | }, | 138 | }, |
129 | 139 | ||
130 | "public": { | 140 | "public": { |
@@ -175,10 +185,6 @@ func resourceStatusCakeTest() *schema.Resource { | |||
175 | "status_codes": { | 185 | "status_codes": { |
176 | Type: schema.TypeString, | 186 | Type: schema.TypeString, |
177 | Optional: true, | 187 | Optional: true, |
178 | Default: "204, 205, 206, 303, 400, 401, 403, 404, 405, 406, " + | ||
179 | "408, 410, 413, 444, 429, 494, 495, 496, 499, 500, 501, 502, 503, " + | ||
180 | "504, 505, 506, 507, 508, 509, 510, 511, 521, 522, 523, 524, 520, " + | ||
181 | "598, 599", | ||
182 | }, | 188 | }, |
183 | 189 | ||
184 | "use_jar": { | 190 | "use_jar": { |
@@ -222,7 +228,7 @@ func CreateTest(d *schema.ResourceData, meta interface{}) error { | |||
222 | UserAgent: d.Get("user_agent").(string), | 228 | UserAgent: d.Get("user_agent").(string), |
223 | Status: d.Get("status").(string), | 229 | Status: d.Get("status").(string), |
224 | Uptime: d.Get("uptime").(float64), | 230 | Uptime: d.Get("uptime").(float64), |
225 | NodeLocations: castInterfaceToSliceStrings(d.Get("node_locations")), | 231 | NodeLocations: castSetToSliceStrings(d.Get("node_locations").(*schema.Set).List()), |
226 | PingURL: d.Get("ping_url").(string), | 232 | PingURL: d.Get("ping_url").(string), |
227 | BasicUser: d.Get("basic_user").(string), | 233 | BasicUser: d.Get("basic_user").(string), |
228 | BasicPass: d.Get("basic_pass").(string), | 234 | BasicPass: d.Get("basic_pass").(string), |
@@ -308,24 +314,19 @@ func ReadTest(d *schema.ResourceData, meta interface{}) error { | |||
308 | d.Set("port", testResp.Port) | 314 | d.Set("port", testResp.Port) |
309 | d.Set("trigger_rate", testResp.TriggerRate) | 315 | d.Set("trigger_rate", testResp.TriggerRate) |
310 | d.Set("custom_header", testResp.CustomHeader) | 316 | d.Set("custom_header", testResp.CustomHeader) |
311 | d.Set("user_agent", testResp.UserAgent) | ||
312 | d.Set("status", testResp.Status) | 317 | d.Set("status", testResp.Status) |
313 | d.Set("uptime", testResp.Uptime) | 318 | d.Set("uptime", testResp.Uptime) |
314 | if err := d.Set("node_locations", testResp.NodeLocations); err != nil { | 319 | if err := d.Set("node_locations", considerEmptyStringAsEmptyArray(testResp.NodeLocations)); err != nil { |
315 | return fmt.Errorf("[WARN] Error setting node locations: %s", err) | 320 | return fmt.Errorf("[WARN] Error setting node locations: %s", err) |
316 | } | 321 | } |
317 | d.Set("ping_url", testResp.PingURL) | ||
318 | d.Set("basic_user", testResp.BasicUser) | ||
319 | d.Set("basic_pass", testResp.BasicPass) | ||
320 | d.Set("public", testResp.Public) | ||
321 | d.Set("logo_image", testResp.LogoImage) | 322 | d.Set("logo_image", testResp.LogoImage) |
322 | d.Set("branding", testResp.Branding) | 323 | // Even after WebsiteHost is set, the API returns "" |
323 | d.Set("website_host", testResp.WebsiteHost) | 324 | // API docs aren't clear on usage will only override state if we get a non-empty value back |
324 | d.Set("virus", testResp.Virus) | 325 | if testResp.WebsiteHost != "" { |
326 | d.Set("website_host", testResp.WebsiteHost) | ||
327 | } | ||
325 | d.Set("find_string", testResp.FindString) | 328 | d.Set("find_string", testResp.FindString) |
326 | d.Set("do_not_find", testResp.DoNotFind) | 329 | d.Set("do_not_find", testResp.DoNotFind) |
327 | d.Set("real_browser", testResp.RealBrowser) | ||
328 | d.Set("test_tags", testResp.TestTags) | ||
329 | d.Set("status_codes", testResp.StatusCodes) | 330 | d.Set("status_codes", testResp.StatusCodes) |
330 | d.Set("use_jar", testResp.UseJar) | 331 | d.Set("use_jar", testResp.UseJar) |
331 | d.Set("post_raw", testResp.PostRaw) | 332 | d.Set("post_raw", testResp.PostRaw) |
@@ -380,7 +381,7 @@ func getStatusCakeTestInput(d *schema.ResourceData) *statuscake.Test { | |||
380 | test.UserAgent = v.(string) | 381 | test.UserAgent = v.(string) |
381 | } | 382 | } |
382 | if v, ok := d.GetOk("node_locations"); ok { | 383 | if v, ok := d.GetOk("node_locations"); ok { |
383 | test.NodeLocations = castInterfaceToSliceStrings(v) | 384 | test.NodeLocations = castSetToSliceStrings(v.(*schema.Set).List()) |
384 | } | 385 | } |
385 | if v, ok := d.GetOk("ping_url"); ok { | 386 | if v, ok := d.GetOk("ping_url"); ok { |
386 | test.PingURL = v.(string) | 387 | test.PingURL = v.(string) |
diff --git a/statuscake/resource_statuscaketest_test.go b/statuscake/resource_statuscaketest_test.go index b727e92..da3a349 100644 --- a/statuscake/resource_statuscaketest_test.go +++ b/statuscake/resource_statuscaketest_test.go | |||
@@ -19,7 +19,7 @@ func TestAccStatusCake_basic(t *testing.T) { | |||
19 | CheckDestroy: testAccTestCheckDestroy(&test), | 19 | CheckDestroy: testAccTestCheckDestroy(&test), |
20 | Steps: []resource.TestStep{ | 20 | Steps: []resource.TestStep{ |
21 | { | 21 | { |
22 | Config: testAccTestConfig_basic, | 22 | Config: fmt.Sprintf(testAccTestConfig_basic, testContactGroupId), |
23 | Check: resource.ComposeTestCheckFunc( | 23 | Check: resource.ComposeTestCheckFunc( |
24 | testAccTestCheckExists("statuscake_test.google", &test), | 24 | testAccTestCheckExists("statuscake_test.google", &test), |
25 | testAccTestCheckAttributes("statuscake_test.google", &test), | 25 | testAccTestCheckAttributes("statuscake_test.google", &test), |
@@ -38,7 +38,7 @@ func TestAccStatusCake_tcp(t *testing.T) { | |||
38 | CheckDestroy: testAccTestCheckDestroy(&test), | 38 | CheckDestroy: testAccTestCheckDestroy(&test), |
39 | Steps: []resource.TestStep{ | 39 | Steps: []resource.TestStep{ |
40 | { | 40 | { |
41 | Config: testAccTestConfig_tcp, | 41 | Config: fmt.Sprintf(testAccTestConfig_tcp, testContactGroupId), |
42 | Check: resource.ComposeTestCheckFunc( | 42 | Check: resource.ComposeTestCheckFunc( |
43 | testAccTestCheckExists("statuscake_test.google", &test), | 43 | testAccTestCheckExists("statuscake_test.google", &test), |
44 | testAccTestCheckAttributes("statuscake_test.google", &test), | 44 | testAccTestCheckAttributes("statuscake_test.google", &test), |
@@ -57,7 +57,7 @@ func TestAccStatusCake_withUpdate(t *testing.T) { | |||
57 | CheckDestroy: testAccTestCheckDestroy(&test), | 57 | CheckDestroy: testAccTestCheckDestroy(&test), |
58 | Steps: []resource.TestStep{ | 58 | Steps: []resource.TestStep{ |
59 | { | 59 | { |
60 | Config: testAccTestConfig_basic, | 60 | Config: fmt.Sprintf(testAccTestConfig_basic, testContactGroupId), |
61 | Check: resource.ComposeTestCheckFunc( | 61 | Check: resource.ComposeTestCheckFunc( |
62 | testAccTestCheckExists("statuscake_test.google", &test), | 62 | testAccTestCheckExists("statuscake_test.google", &test), |
63 | ), | 63 | ), |
@@ -76,12 +76,9 @@ func TestAccStatusCake_withUpdate(t *testing.T) { | |||
76 | resource.TestCheckResourceAttr("statuscake_test.google", "trigger_rate", "20"), | 76 | resource.TestCheckResourceAttr("statuscake_test.google", "trigger_rate", "20"), |
77 | resource.TestCheckResourceAttr("statuscake_test.google", "custom_header", "{ \"Content-Type\": \"application/x-www-form-urlencoded\" }"), | 77 | resource.TestCheckResourceAttr("statuscake_test.google", "custom_header", "{ \"Content-Type\": \"application/x-www-form-urlencoded\" }"), |
78 | resource.TestCheckResourceAttr("statuscake_test.google", "user_agent", "string9988"), | 78 | resource.TestCheckResourceAttr("statuscake_test.google", "user_agent", "string9988"), |
79 | resource.TestCheckResourceAttr("statuscake_test.google", "status", "string22117"), | 79 | resource.TestCheckResourceAttr("statuscake_test.google", "status", "Up"), |
80 | resource.TestCheckResourceAttr("statuscake_test.google", "uptime", "3498.27"), | 80 | resource.TestCheckResourceAttr("statuscake_test.google", "uptime", "0"), |
81 | resource.TestCheckResourceAttr("statuscake_test.google", "node_locations.#", "3"), | 81 | resource.TestCheckResourceAttr("statuscake_test.google", "node_locations.#", "3"), |
82 | resource.TestCheckResourceAttr("statuscake_test.google", "node_locations.0", "string16045"), | ||
83 | resource.TestCheckResourceAttr("statuscake_test.google", "node_locations.1", "string19741"), | ||
84 | resource.TestCheckResourceAttr("statuscake_test.google", "node_locations.2", "string12122"), | ||
85 | resource.TestCheckResourceAttr("statuscake_test.google", "ping_url", "string8410"), | 82 | resource.TestCheckResourceAttr("statuscake_test.google", "ping_url", "string8410"), |
86 | resource.TestCheckResourceAttr("statuscake_test.google", "basic_user", "string27052"), | 83 | resource.TestCheckResourceAttr("statuscake_test.google", "basic_user", "string27052"), |
87 | resource.TestCheckResourceAttr("statuscake_test.google", "basic_pass", "string5659"), | 84 | resource.TestCheckResourceAttr("statuscake_test.google", "basic_pass", "string5659"), |
@@ -169,8 +166,6 @@ func testAccTestCheckAttributes(rn string, test *statuscake.Test) resource.TestC | |||
169 | err = check(key, value, strconv.Itoa(test.TriggerRate)) | 166 | err = check(key, value, strconv.Itoa(test.TriggerRate)) |
170 | case "custom_header": | 167 | case "custom_header": |
171 | err = check(key, value, test.CustomHeader) | 168 | err = check(key, value, test.CustomHeader) |
172 | case "user_agent": | ||
173 | err = check(key, value, test.UserAgent) | ||
174 | case "node_locations": | 169 | case "node_locations": |
175 | for _, tv := range test.NodeLocations { | 170 | for _, tv := range test.NodeLocations { |
176 | err = check(key, value, tv) | 171 | err = check(key, value, tv) |
@@ -178,30 +173,14 @@ func testAccTestCheckAttributes(rn string, test *statuscake.Test) resource.TestC | |||
178 | return err | 173 | return err |
179 | } | 174 | } |
180 | } | 175 | } |
181 | case "ping_url": | ||
182 | err = check(key, value, test.PingURL) | ||
183 | case "basic_user": | ||
184 | err = check(key, value, test.BasicUser) | ||
185 | case "basic_pass": | ||
186 | err = check(key, value, test.BasicPass) | ||
187 | case "public": | 176 | case "public": |
188 | err = check(key, value, strconv.Itoa(test.Public)) | 177 | err = check(key, value, strconv.Itoa(test.Public)) |
189 | case "logo_image": | 178 | case "logo_image": |
190 | err = check(key, value, test.LogoImage) | 179 | err = check(key, value, test.LogoImage) |
191 | case "branding": | ||
192 | err = check(key, value, strconv.Itoa(test.Branding)) | ||
193 | case "website_host": | ||
194 | err = check(key, value, test.WebsiteHost) | ||
195 | case "virus": | ||
196 | err = check(key, value, strconv.Itoa(test.Virus)) | ||
197 | case "find_string": | 180 | case "find_string": |
198 | err = check(key, value, test.FindString) | 181 | err = check(key, value, test.FindString) |
199 | case "do_not_find": | 182 | case "do_not_find": |
200 | err = check(key, value, strconv.FormatBool(test.DoNotFind)) | 183 | err = check(key, value, strconv.FormatBool(test.DoNotFind)) |
201 | case "real_browser": | ||
202 | err = check(key, value, strconv.Itoa(test.RealBrowser)) | ||
203 | case "test_tags": | ||
204 | err = check(key, value, test.TestTags) | ||
205 | case "status_codes": | 184 | case "status_codes": |
206 | err = check(key, value, test.StatusCodes) | 185 | err = check(key, value, test.StatusCodes) |
207 | case "use_jar": | 186 | case "use_jar": |
@@ -240,7 +219,7 @@ resource "statuscake_test" "google" { | |||
240 | test_type = "HTTP" | 219 | test_type = "HTTP" |
241 | check_rate = 300 | 220 | check_rate = 300 |
242 | timeout = 10 | 221 | timeout = 10 |
243 | contact_id = 43402 | 222 | contact_id = %d |
244 | confirmations = 1 | 223 | confirmations = 1 |
245 | trigger_rate = 10 | 224 | trigger_rate = 10 |
246 | } | 225 | } |
@@ -284,7 +263,7 @@ resource "statuscake_test" "google" { | |||
284 | test_type = "TCP" | 263 | test_type = "TCP" |
285 | check_rate = 300 | 264 | check_rate = 300 |
286 | timeout = 10 | 265 | timeout = 10 |
287 | contact_id = 43402 | 266 | contact_id = %d |
288 | confirmations = 1 | 267 | confirmations = 1 |
289 | port = 80 | 268 | port = 80 |
290 | } | 269 | } |