aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--statuscake/resource_statuscaketest.go258
-rw-r--r--statuscake/resource_statuscaketest_test.go103
2 files changed, 335 insertions, 26 deletions
diff --git a/statuscake/resource_statuscaketest.go b/statuscake/resource_statuscaketest.go
index 101ee83..27cf9bf 100644
--- a/statuscake/resource_statuscaketest.go
+++ b/statuscake/resource_statuscaketest.go
@@ -34,7 +34,7 @@ func resourceStatusCakeTest() *schema.Resource {
34 }, 34 },
35 35
36 "contact_id": { 36 "contact_id": {
37 Type: schema.TypeInt, 37 Type: schema.TypeString,
38 Optional: true, 38 Optional: true,
39 }, 39 },
40 40
@@ -76,6 +76,120 @@ func resourceStatusCakeTest() *schema.Resource {
76 Optional: true, 76 Optional: true,
77 Default: 5, 77 Default: 5,
78 }, 78 },
79 "custom_header": {
80 Type: schema.TypeString,
81 Optional: true,
82 },
83
84 "user_agent": {
85 Type: schema.TypeString,
86 Optional: true,
87 },
88
89 "status": {
90 Type: schema.TypeString,
91 Optional: true,
92 },
93
94 "uptime": {
95 Type: schema.TypeFloat,
96 Optional: true,
97 },
98
99 "node_locations": {
100 Type: schema.TypeList,
101 Elem: &schema.Schema{Type: schema.TypeString},
102 Optional: true,
103 },
104
105 "ping_url": {
106 Type: schema.TypeString,
107 Optional: true,
108 },
109
110 "basic_user": {
111 Type: schema.TypeString,
112 Optional: true,
113 },
114
115 "basic_pass": {
116 Type: schema.TypeString,
117 Optional: true,
118 },
119
120 "public": {
121 Type: schema.TypeInt,
122 Optional: true,
123 },
124
125 "logo_image": {
126 Type: schema.TypeString,
127 Optional: true,
128 },
129
130 "branding": {
131 Type: schema.TypeInt,
132 Optional: true,
133 },
134
135 "website_host": {
136 Type: schema.TypeString,
137 Optional: true,
138 },
139
140 "virus": {
141 Type: schema.TypeInt,
142 Optional: true,
143 },
144
145 "find_string": {
146 Type: schema.TypeString,
147 Optional: true,
148 },
149
150 "do_not_find": {
151 Type: schema.TypeBool,
152 Optional: true,
153 },
154
155 "real_browser": {
156 Type: schema.TypeInt,
157 Optional: true,
158 },
159
160 "test_tags": {
161 Type: schema.TypeString,
162 Optional: true,
163 },
164
165 "status_codes": {
166 Type: schema.TypeString,
167 Optional: true,
168 Default: "204, 205, 206, 303, 400, 401, 403, 404, 405, 406, " +
169 "408, 410, 413, 444, 429, 494, 495, 496, 499, 500, 501, 502, 503, " +
170 "504, 505, 506, 507, 508, 509, 510, 511, 521, 522, 523, 524, 520, " +
171 "598, 599",
172 },
173
174 "use_jar": {
175 Type: schema.TypeInt,
176 Optional: true,
177 },
178
179 "post_raw": {
180 Type: schema.TypeString,
181 Optional: true,
182 },
183
184 "final_endpoint": {
185 Type: schema.TypeString,
186 Optional: true,
187 },
188
189 "follow_redirect": {
190 Type: schema.TypeBool,
191 Optional: true,
192 },
79 }, 193 },
80 } 194 }
81} 195}
@@ -84,16 +198,38 @@ func CreateTest(d *schema.ResourceData, meta interface{}) error {
84 client := meta.(*statuscake.Client) 198 client := meta.(*statuscake.Client)
85 199
86 newTest := &statuscake.Test{ 200 newTest := &statuscake.Test{
87 WebsiteName: d.Get("website_name").(string), 201 WebsiteName: d.Get("website_name").(string),
88 WebsiteURL: d.Get("website_url").(string), 202 WebsiteURL: d.Get("website_url").(string),
89 CheckRate: d.Get("check_rate").(int), 203 CheckRate: d.Get("check_rate").(int),
90 TestType: d.Get("test_type").(string), 204 TestType: d.Get("test_type").(string),
91 Paused: d.Get("paused").(bool), 205 Paused: d.Get("paused").(bool),
92 Timeout: d.Get("timeout").(int), 206 Timeout: d.Get("timeout").(int),
93 ContactID: d.Get("contact_id").(int), 207 ContactID: d.Get("contact_id").(string),
94 Confirmation: d.Get("confirmations").(int), 208 Confirmation: d.Get("confirmations").(int),
95 Port: d.Get("port").(int), 209 Port: d.Get("port").(int),
96 TriggerRate: d.Get("trigger_rate").(int), 210 TriggerRate: d.Get("trigger_rate").(int),
211 CustomHeader: d.Get("custom_header").(string),
212 UserAgent: d.Get("user_agent").(string),
213 Status: d.Get("status").(string),
214 Uptime: d.Get("uptime").(float64),
215 NodeLocations: d.Get("node_locations").([]string),
216 PingURL: d.Get("ping_url").(string),
217 BasicUser: d.Get("basic_user").(string),
218 BasicPass: d.Get("basic_pass").(string),
219 Public: d.Get("public").(int),
220 LogoImage: d.Get("logo_image").(string),
221 Branding: d.Get("branding").(int),
222 WebsiteHost: d.Get("website_host").(string),
223 Virus: d.Get("virus").(int),
224 FindString: d.Get("find_string").(string),
225 DoNotFind: d.Get("do_not_find").(bool),
226 RealBrowser: d.Get("real_browser").(int),
227 TestTags: d.Get("test_tags").(string),
228 StatusCodes: d.Get("status_codes").(string),
229 UseJar: d.Get("use_jar").(int),
230 PostRaw: d.Get("post_raw").(string),
231 FinalEndpoint: d.Get("final_endpoint").(string),
232 FollowRedirect: d.Get("follow_redirect").(bool),
97 } 233 }
98 234
99 log.Printf("[DEBUG] Creating new StatusCake Test: %s", d.Get("website_name").(string)) 235 log.Printf("[DEBUG] Creating new StatusCake Test: %s", d.Get("website_name").(string))
@@ -159,6 +295,28 @@ func ReadTest(d *schema.ResourceData, meta interface{}) error {
159 d.Set("confirmations", testResp.Confirmation) 295 d.Set("confirmations", testResp.Confirmation)
160 d.Set("port", testResp.Port) 296 d.Set("port", testResp.Port)
161 d.Set("trigger_rate", testResp.TriggerRate) 297 d.Set("trigger_rate", testResp.TriggerRate)
298 d.Set("custom_header", testResp.CustomHeader)
299 d.Set("user_agent", testResp.UserAgent)
300 d.Set("status", testResp.Status)
301 d.Set("uptime", testResp.Uptime)
302 d.Set("node_locations", testResp.NodeLocations)
303 d.Set("ping_url", testResp.PingURL)
304 d.Set("basic_user", testResp.BasicUser)
305 d.Set("basic_pass", testResp.BasicPass)
306 d.Set("public", testResp.Public)
307 d.Set("logo_image", testResp.LogoImage)
308 d.Set("branding", testResp.Branding)
309 d.Set("website_host", testResp.WebsiteHost)
310 d.Set("virus", testResp.Virus)
311 d.Set("find_string", testResp.FindString)
312 d.Set("do_not_find", testResp.DoNotFind)
313 d.Set("real_browser", testResp.RealBrowser)
314 d.Set("test_tags", testResp.TestTags)
315 d.Set("status_codes", testResp.StatusCodes)
316 d.Set("use_jar", testResp.UseJar)
317 d.Set("post_raw", testResp.PostRaw)
318 d.Set("final_endpoint", testResp.FinalEndpoint)
319 d.Set("follow_redirect", testResp.FollowRedirect)
162 320
163 return nil 321 return nil
164} 322}
@@ -181,7 +339,7 @@ func getStatusCakeTestInput(d *schema.ResourceData) *statuscake.Test {
181 test.CheckRate = v.(int) 339 test.CheckRate = v.(int)
182 } 340 }
183 if v, ok := d.GetOk("contact_id"); ok { 341 if v, ok := d.GetOk("contact_id"); ok {
184 test.ContactID = v.(int) 342 test.ContactID = v.(string)
185 } 343 }
186 if v, ok := d.GetOk("test_type"); ok { 344 if v, ok := d.GetOk("test_type"); ok {
187 test.TestType = v.(string) 345 test.TestType = v.(string)
@@ -192,9 +350,6 @@ func getStatusCakeTestInput(d *schema.ResourceData) *statuscake.Test {
192 if v, ok := d.GetOk("timeout"); ok { 350 if v, ok := d.GetOk("timeout"); ok {
193 test.Timeout = v.(int) 351 test.Timeout = v.(int)
194 } 352 }
195 if v, ok := d.GetOk("contact_id"); ok {
196 test.ContactID = v.(int)
197 }
198 if v, ok := d.GetOk("confirmations"); ok { 353 if v, ok := d.GetOk("confirmations"); ok {
199 test.Confirmation = v.(int) 354 test.Confirmation = v.(int)
200 } 355 }
@@ -204,13 +359,72 @@ func getStatusCakeTestInput(d *schema.ResourceData) *statuscake.Test {
204 if v, ok := d.GetOk("trigger_rate"); ok { 359 if v, ok := d.GetOk("trigger_rate"); ok {
205 test.TriggerRate = v.(int) 360 test.TriggerRate = v.(int)
206 } 361 }
207 362 if v, ok := d.GetOk("custom_header"); ok {
208 defaultStatusCodes := "204, 205, 206, 303, 400, 401, 403, 404, 405, 406, " + 363 test.CustomHeader = v.(string)
209 "408, 410, 413, 444, 429, 494, 495, 496, 499, 500, 501, 502, 503, " + 364 }
210 "504, 505, 506, 507, 508, 509, 510, 511, 521, 522, 523, 524, 520, " + 365 if v, ok := d.GetOk("user_agent"); ok {
211 "598, 599" 366 test.UserAgent = v.(string)
212 367 }
213 test.StatusCodes = defaultStatusCodes 368 if v, ok := d.GetOk("status"); ok {
369 test.Status = v.(string)
370 }
371 if v, ok := d.GetOk("uptime"); ok {
372 test.Uptime = v.(float64)
373 }
374 if v, ok := d.GetOk("node_locations"); ok {
375 test.NodeLocations = v.([]string)
376 }
377 if v, ok := d.GetOk("ping_url"); ok {
378 test.PingURL = v.(string)
379 }
380 if v, ok := d.GetOk("basic_user"); ok {
381 test.BasicUser = v.(string)
382 }
383 if v, ok := d.GetOk("basic_pass"); ok {
384 test.BasicPass = v.(string)
385 }
386 if v, ok := d.GetOk("public"); ok {
387 test.Public = v.(int)
388 }
389 if v, ok := d.GetOk("logo_image"); ok {
390 test.LogoImage = v.(string)
391 }
392 if v, ok := d.GetOk("branding"); ok {
393 test.Branding = v.(int)
394 }
395 if v, ok := d.GetOk("website_host"); ok {
396 test.WebsiteHost = v.(string)
397 }
398 if v, ok := d.GetOk("virus"); ok {
399 test.Virus = v.(int)
400 }
401 if v, ok := d.GetOk("find_string"); ok {
402 test.FindString = v.(string)
403 }
404 if v, ok := d.GetOk("do_not_find"); ok {
405 test.DoNotFind = v.(bool)
406 }
407 if v, ok := d.GetOk("real_browser"); ok {
408 test.RealBrowser = v.(int)
409 }
410 if v, ok := d.GetOk("test_tags"); ok {
411 test.TestTags = v.(string)
412 }
413 if v, ok := d.GetOk("status_codes"); ok {
414 test.StatusCodes = v.(string)
415 }
416 if v, ok := d.GetOk("use_jar"); ok {
417 test.UseJar = v.(int)
418 }
419 if v, ok := d.GetOk("post_raw"); ok {
420 test.PostRaw = v.(string)
421 }
422 if v, ok := d.GetOk("final_endpoint"); ok {
423 test.FinalEndpoint = v.(string)
424 }
425 if v, ok := d.GetOk("follow_redirect"); ok {
426 test.FollowRedirect = v.(bool)
427 }
214 428
215 return test 429 return test
216} 430}
diff --git a/statuscake/resource_statuscaketest_test.go b/statuscake/resource_statuscaketest_test.go
index f07fcc5..b39d23c 100644
--- a/statuscake/resource_statuscaketest_test.go
+++ b/statuscake/resource_statuscaketest_test.go
@@ -74,6 +74,31 @@ func TestAccStatusCake_withUpdate(t *testing.T) {
74 resource.TestCheckResourceAttr("statuscake_test.google", "contact_id", "0"), 74 resource.TestCheckResourceAttr("statuscake_test.google", "contact_id", "0"),
75 resource.TestCheckResourceAttr("statuscake_test.google", "confirmations", "0"), 75 resource.TestCheckResourceAttr("statuscake_test.google", "confirmations", "0"),
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\" }"),
78 resource.TestCheckResourceAttr("statuscake_test.google", "user_agent", "string9988"),
79 resource.TestCheckResourceAttr("statuscake_test.google", "status", "string22117"),
80 resource.TestCheckResourceAttr("statuscake_test.google", "uptime", "3498.27"),
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"),
86 resource.TestCheckResourceAttr("statuscake_test.google", "basic_user", "string27052"),
87 resource.TestCheckResourceAttr("statuscake_test.google", "basic_pass", "string5659"),
88 resource.TestCheckResourceAttr("statuscake_test.google", "public", "0"),
89 resource.TestCheckResourceAttr("statuscake_test.google", "logo_image", "string21087"),
90 resource.TestCheckResourceAttr("statuscake_test.google", "branding", "25875"),
91 resource.TestCheckResourceAttr("statuscake_test.google", "website_host", "string32368"),
92 resource.TestCheckResourceAttr("statuscake_test.google", "virus", "1"),
93 resource.TestCheckResourceAttr("statuscake_test.google", "find_string", "string15212"),
94 resource.TestCheckResourceAttr("statuscake_test.google", "do_not_find", "false"),
95 resource.TestCheckResourceAttr("statuscake_test.google", "real_browser", "1"),
96 resource.TestCheckResourceAttr("statuscake_test.google", "test_tags", "string8191"),
97 resource.TestCheckResourceAttr("statuscake_test.google", "status_codes", "string23065"),
98 resource.TestCheckResourceAttr("statuscake_test.google", "use_jar", "1"),
99 resource.TestCheckResourceAttr("statuscake_test.google", "post_raw", "string32096"),
100 resource.TestCheckResourceAttr("statuscake_test.google", "final_endpoint", "string10781"),
101 resource.TestCheckResourceAttr("statuscake_test.google", "follow_redirect", "true"),
77 ), 102 ),
78 }, 103 },
79 }, 104 },
@@ -137,13 +162,61 @@ func testAccTestCheckAttributes(rn string, test *statuscake.Test) resource.TestC
137 case "timeout": 162 case "timeout":
138 err = check(key, value, strconv.Itoa(test.Timeout)) 163 err = check(key, value, strconv.Itoa(test.Timeout))
139 case "contact_id": 164 case "contact_id":
140 err = check(key, value, strconv.Itoa(test.ContactID)) 165 err = check(key, value, test.ContactID)
141 case "confirmations": 166 case "confirmations":
142 err = check(key, value, strconv.Itoa(test.Confirmation)) 167 err = check(key, value, strconv.Itoa(test.Confirmation))
143 case "trigger_rate": 168 case "trigger_rate":
144 err = check(key, value, strconv.Itoa(test.TriggerRate)) 169 err = check(key, value, strconv.Itoa(test.TriggerRate))
170 case "custom_header":
171 err = check(key, value, test.CustomHeader)
172 case "user_agent":
173 err = check(key, value, test.UserAgent)
174 case "status":
175 err = check(key, value, test.Status)
176 case "uptime":
177 err = check(key, value, strconv.FormatFloat(test.Uptime, 'f', -1, 64))
178 case "node_locations":
179 for _, tv := range test.NodeLocations {
180 err = check(key, value, tv)
181 if err != nil {
182 return err
183 }
184 }
185 case "ping_url":
186 err = check(key, value, test.PingURL)
187 case "basic_user":
188 err = check(key, value, test.BasicUser)
189 case "basic_pass":
190 err = check(key, value, test.BasicPass)
191 case "public":
192 err = check(key, value, strconv.Itoa(test.Public))
193 case "logo_image":
194 err = check(key, value, test.LogoImage)
195 case "branding":
196 err = check(key, value, strconv.Itoa(test.Branding))
197 case "website_host":
198 err = check(key, value, test.WebsiteHost)
199 case "virus":
200 err = check(key, value, strconv.Itoa(test.Virus))
201 case "find_string":
202 err = check(key, value, test.FindString)
203 case "do_not_find":
204 err = check(key, value, strconv.FormatBool(test.DoNotFind))
205 case "real_browser":
206 err = check(key, value, strconv.Itoa(test.RealBrowser))
207 case "test_tags":
208 err = check(key, value, test.TestTags)
209 case "status_codes":
210 err = check(key, value, test.StatusCodes)
211 case "use_jar":
212 err = check(key, value, strconv.Itoa(test.UseJar))
213 case "post_raw":
214 err = check(key, value, test.PostRaw)
215 case "final_endpoint":
216 err = check(key, value, test.FinalEndpoint)
217 case "follow_redirect":
218 err = check(key, value, strconv.FormatBool(test.FollowRedirect))
145 } 219 }
146
147 if err != nil { 220 if err != nil {
148 return err 221 return err
149 } 222 }
@@ -171,7 +244,7 @@ resource "statuscake_test" "google" {
171 test_type = "HTTP" 244 test_type = "HTTP"
172 check_rate = 300 245 check_rate = 300
173 timeout = 10 246 timeout = 10
174 contact_id = 43402 247 contact_id = "43402"
175 confirmations = 1 248 confirmations = 1
176 trigger_rate = 10 249 trigger_rate = 10
177} 250}
@@ -185,6 +258,28 @@ resource "statuscake_test" "google" {
185 check_rate = 500 258 check_rate = 500
186 paused = true 259 paused = true
187 trigger_rate = 20 260 trigger_rate = 20
261 custom_header = "{ \"Content-Type\": \"application/x-www-form-urlencoded\" }"
262 user_agent = "string9988"
263 status = "string22117"
264 uptime = 3498.27
265 node_locations = [ "string16045", "string19741", "string12122" ]
266 ping_url = "string8410"
267 basic_user = "string27052"
268 basic_pass = "string5659"
269 public = 0
270 logo_image = "string21087"
271 branding = 25875
272 website_host = "string32368"
273 virus = 1
274 find_string = "string15212"
275 do_not_find = false
276 real_browser = 1
277 test_tags = "string8191"
278 status_codes = "string23065"
279 use_jar = 1
280 post_raw = "string32096"
281 final_endpoint = "string10781"
282 follow_redirect = true
188} 283}
189` 284`
190 285
@@ -195,7 +290,7 @@ resource "statuscake_test" "google" {
195 test_type = "TCP" 290 test_type = "TCP"
196 check_rate = 300 291 check_rate = 300
197 timeout = 10 292 timeout = 10
198 contact_id = 43402 293 contact_id = "43402"
199 confirmations = 1 294 confirmations = 1
200 port = 80 295 port = 80
201} 296}