aboutsummaryrefslogtreecommitdiffhomepage
path: root/statuscake/resource_statuscaketest_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'statuscake/resource_statuscaketest_test.go')
-rw-r--r--statuscake/resource_statuscaketest_test.go94
1 files changed, 88 insertions, 6 deletions
diff --git a/statuscake/resource_statuscaketest_test.go b/statuscake/resource_statuscaketest_test.go
index f07fcc5..8bcbb36 100644
--- a/statuscake/resource_statuscaketest_test.go
+++ b/statuscake/resource_statuscaketest_test.go
@@ -2,6 +2,7 @@ package statuscake
2 2
3import ( 3import (
4 "fmt" 4 "fmt"
5 "os"
5 "strconv" 6 "strconv"
6 "testing" 7 "testing"
7 8
@@ -19,7 +20,7 @@ func TestAccStatusCake_basic(t *testing.T) {
19 CheckDestroy: testAccTestCheckDestroy(&test), 20 CheckDestroy: testAccTestCheckDestroy(&test),
20 Steps: []resource.TestStep{ 21 Steps: []resource.TestStep{
21 { 22 {
22 Config: testAccTestConfig_basic, 23 Config: interpolateTerraformTemplate(testAccTestConfig_basic),
23 Check: resource.ComposeTestCheckFunc( 24 Check: resource.ComposeTestCheckFunc(
24 testAccTestCheckExists("statuscake_test.google", &test), 25 testAccTestCheckExists("statuscake_test.google", &test),
25 testAccTestCheckAttributes("statuscake_test.google", &test), 26 testAccTestCheckAttributes("statuscake_test.google", &test),
@@ -38,7 +39,7 @@ func TestAccStatusCake_tcp(t *testing.T) {
38 CheckDestroy: testAccTestCheckDestroy(&test), 39 CheckDestroy: testAccTestCheckDestroy(&test),
39 Steps: []resource.TestStep{ 40 Steps: []resource.TestStep{
40 { 41 {
41 Config: testAccTestConfig_tcp, 42 Config: interpolateTerraformTemplate(testAccTestConfig_tcp),
42 Check: resource.ComposeTestCheckFunc( 43 Check: resource.ComposeTestCheckFunc(
43 testAccTestCheckExists("statuscake_test.google", &test), 44 testAccTestCheckExists("statuscake_test.google", &test),
44 testAccTestCheckAttributes("statuscake_test.google", &test), 45 testAccTestCheckAttributes("statuscake_test.google", &test),
@@ -57,7 +58,7 @@ func TestAccStatusCake_withUpdate(t *testing.T) {
57 CheckDestroy: testAccTestCheckDestroy(&test), 58 CheckDestroy: testAccTestCheckDestroy(&test),
58 Steps: []resource.TestStep{ 59 Steps: []resource.TestStep{
59 { 60 {
60 Config: testAccTestConfig_basic, 61 Config: interpolateTerraformTemplate(testAccTestConfig_basic),
61 Check: resource.ComposeTestCheckFunc( 62 Check: resource.ComposeTestCheckFunc(
62 testAccTestCheckExists("statuscake_test.google", &test), 63 testAccTestCheckExists("statuscake_test.google", &test),
63 ), 64 ),
@@ -74,6 +75,28 @@ func TestAccStatusCake_withUpdate(t *testing.T) {
74 resource.TestCheckResourceAttr("statuscake_test.google", "contact_id", "0"), 75 resource.TestCheckResourceAttr("statuscake_test.google", "contact_id", "0"),
75 resource.TestCheckResourceAttr("statuscake_test.google", "confirmations", "0"), 76 resource.TestCheckResourceAttr("statuscake_test.google", "confirmations", "0"),
76 resource.TestCheckResourceAttr("statuscake_test.google", "trigger_rate", "20"), 77 resource.TestCheckResourceAttr("statuscake_test.google", "trigger_rate", "20"),
78 resource.TestCheckResourceAttr("statuscake_test.google", "custom_header", "{ \"Content-Type\": \"application/x-www-form-urlencoded\" }"),
79 resource.TestCheckResourceAttr("statuscake_test.google", "user_agent", "string9988"),
80 resource.TestCheckResourceAttr("statuscake_test.google", "status", "Up"),
81 resource.TestCheckResourceAttr("statuscake_test.google", "uptime", "0"),
82 resource.TestCheckResourceAttr("statuscake_test.google", "node_locations.#", "3"),
83 resource.TestCheckResourceAttr("statuscake_test.google", "ping_url", "string8410"),
84 resource.TestCheckResourceAttr("statuscake_test.google", "basic_user", "string27052"),
85 resource.TestCheckResourceAttr("statuscake_test.google", "basic_pass", "string5659"),
86 resource.TestCheckResourceAttr("statuscake_test.google", "public", "0"),
87 resource.TestCheckResourceAttr("statuscake_test.google", "logo_image", "string21087"),
88 resource.TestCheckResourceAttr("statuscake_test.google", "branding", "25875"),
89 resource.TestCheckResourceAttr("statuscake_test.google", "website_host", "string32368"),
90 resource.TestCheckResourceAttr("statuscake_test.google", "virus", "1"),
91 resource.TestCheckResourceAttr("statuscake_test.google", "find_string", "string15212"),
92 resource.TestCheckResourceAttr("statuscake_test.google", "do_not_find", "false"),
93 resource.TestCheckResourceAttr("statuscake_test.google", "real_browser", "1"),
94 resource.TestCheckResourceAttr("statuscake_test.google", "test_tags", "string8191"),
95 resource.TestCheckResourceAttr("statuscake_test.google", "status_codes", "string23065"),
96 resource.TestCheckResourceAttr("statuscake_test.google", "use_jar", "1"),
97 resource.TestCheckResourceAttr("statuscake_test.google", "post_raw", "string32096"),
98 resource.TestCheckResourceAttr("statuscake_test.google", "final_endpoint", "string10781"),
99 resource.TestCheckResourceAttr("statuscake_test.google", "follow_redirect", "true"),
77 ), 100 ),
78 }, 101 },
79 }, 102 },
@@ -142,8 +165,34 @@ func testAccTestCheckAttributes(rn string, test *statuscake.Test) resource.TestC
142 err = check(key, value, strconv.Itoa(test.Confirmation)) 165 err = check(key, value, strconv.Itoa(test.Confirmation))
143 case "trigger_rate": 166 case "trigger_rate":
144 err = check(key, value, strconv.Itoa(test.TriggerRate)) 167 err = check(key, value, strconv.Itoa(test.TriggerRate))
168 case "custom_header":
169 err = check(key, value, test.CustomHeader)
170 case "node_locations":
171 for _, tv := range test.NodeLocations {
172 err = check(key, value, tv)
173 if err != nil {
174 return err
175 }
176 }
177 case "public":
178 err = check(key, value, strconv.Itoa(test.Public))
179 case "logo_image":
180 err = check(key, value, test.LogoImage)
181 case "find_string":
182 err = check(key, value, test.FindString)
183 case "do_not_find":
184 err = check(key, value, strconv.FormatBool(test.DoNotFind))
185 case "status_codes":
186 err = check(key, value, test.StatusCodes)
187 case "use_jar":
188 err = check(key, value, strconv.Itoa(test.UseJar))
189 case "post_raw":
190 err = check(key, value, test.PostRaw)
191 case "final_endpoint":
192 err = check(key, value, test.FinalEndpoint)
193 case "follow_redirect":
194 err = check(key, value, strconv.FormatBool(test.FollowRedirect))
145 } 195 }
146
147 if err != nil { 196 if err != nil {
148 return err 197 return err
149 } 198 }
@@ -164,6 +213,19 @@ func testAccTestCheckDestroy(test *statuscake.Test) resource.TestCheckFunc {
164 } 213 }
165} 214}
166 215
216func interpolateTerraformTemplate(template string) string {
217 testContactGroupId := 43402
218
219 if v := os.Getenv("STATUSCAKE_TEST_CONTACT_GROUP_ID"); v != "" {
220 id, err := strconv.Atoi(v)
221 if err == nil {
222 testContactGroupId = id
223 }
224 }
225
226 return fmt.Sprintf(template, testContactGroupId)
227}
228
167const testAccTestConfig_basic = ` 229const testAccTestConfig_basic = `
168resource "statuscake_test" "google" { 230resource "statuscake_test" "google" {
169 website_name = "google.com" 231 website_name = "google.com"
@@ -171,7 +233,7 @@ resource "statuscake_test" "google" {
171 test_type = "HTTP" 233 test_type = "HTTP"
172 check_rate = 300 234 check_rate = 300
173 timeout = 10 235 timeout = 10
174 contact_id = 43402 236 contact_id = %d
175 confirmations = 1 237 confirmations = 1
176 trigger_rate = 10 238 trigger_rate = 10
177} 239}
@@ -185,6 +247,26 @@ resource "statuscake_test" "google" {
185 check_rate = 500 247 check_rate = 500
186 paused = true 248 paused = true
187 trigger_rate = 20 249 trigger_rate = 20
250 custom_header = "{ \"Content-Type\": \"application/x-www-form-urlencoded\" }"
251 user_agent = "string9988"
252 node_locations = [ "string16045", "string19741", "string12122" ]
253 ping_url = "string8410"
254 basic_user = "string27052"
255 basic_pass = "string5659"
256 public = 0
257 logo_image = "string21087"
258 branding = 25875
259 website_host = "string32368"
260 virus = 1
261 find_string = "string15212"
262 do_not_find = false
263 real_browser = 1
264 test_tags = "string8191"
265 status_codes = "string23065"
266 use_jar = 1
267 post_raw = "string32096"
268 final_endpoint = "string10781"
269 follow_redirect = true
188} 270}
189` 271`
190 272
@@ -195,7 +277,7 @@ resource "statuscake_test" "google" {
195 test_type = "TCP" 277 test_type = "TCP"
196 check_rate = 300 278 check_rate = 300
197 timeout = 10 279 timeout = 10
198 contact_id = 43402 280 contact_id = %d
199 confirmations = 1 281 confirmations = 1
200 port = 80 282 port = 80
201} 283}