aboutsummaryrefslogtreecommitdiffhomepage
path: root/resource_statuscaketest_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'resource_statuscaketest_test.go')
-rw-r--r--resource_statuscaketest_test.go83
1 files changed, 83 insertions, 0 deletions
diff --git a/resource_statuscaketest_test.go b/resource_statuscaketest_test.go
index bbc6932..4123ac6 100644
--- a/resource_statuscaketest_test.go
+++ b/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
@@ -10,6 +11,19 @@ import (
10 "github.com/hashicorp/terraform/terraform" 11 "github.com/hashicorp/terraform/terraform"
11) 12)
12 13
14// check to ensure that contact group id is provided before running
15// tests on it.
16func testAccContactGroupPreCheck(t *testing.T, testAlt bool) {
17 if v := os.Getenv("CONTACT_GROUP"); v == "" {
18 t.Fatal("CONTACT_GROUP must be set for contact group acceptance tests")
19 }
20 if testAlt {
21 if v := os.Getenv("ALT_CONTACT_GROUP"); v == "" {
22 t.Fatal("ALT_CONTACT_GROUP must be set for contact group acceptance tests")
23 }
24 }
25}
26
13func TestAccStatusCake_basic(t *testing.T) { 27func TestAccStatusCake_basic(t *testing.T) {
14 var test statuscake.Test 28 var test statuscake.Test
15 29
@@ -55,6 +69,57 @@ func TestAccStatusCake_withUpdate(t *testing.T) {
55 }) 69 })
56} 70}
57 71
72func TestAccStatusCake_contactGroup_basic(t *testing.T) {
73 var test statuscake.Test
74
75 resource.Test(t, resource.TestCase{
76 PreCheck: func() {
77 testAccPreCheck(t)
78 testAccContactGroupPreCheck(t, false)
79 },
80 Providers: testAccProviders,
81 CheckDestroy: testAccTestCheckDestroy(&test),
82 Steps: []resource.TestStep{
83 resource.TestStep{
84 Config: testAccTestConfig_contactGroup,
85 Check: resource.ComposeTestCheckFunc(
86 testAccTestCheckExists("statuscake_test.google", &test),
87 ),
88 },
89 },
90 })
91}
92
93func TestAccStatusCake_contactGroup_withUpdate(t *testing.T) {
94 var test statuscake.Test
95 var altContactGroup = os.Getenv("ALT_CONTACT_GROUP")
96
97 resource.Test(t, resource.TestCase{
98 PreCheck: func() {
99 testAccPreCheck(t)
100 testAccContactGroupPreCheck(t, true)
101 },
102 Providers: testAccProviders,
103 CheckDestroy: testAccTestCheckDestroy(&test),
104 Steps: []resource.TestStep{
105 resource.TestStep{
106 Config: testAccTestConfig_contactGroup,
107 Check: resource.ComposeTestCheckFunc(
108 testAccTestCheckExists("statuscake_test.google", &test),
109 ),
110 },
111 // make sure to creat
112 resource.TestStep{
113 Config: testAccTestConfig_contactGroup_update,
114 Check: resource.ComposeTestCheckFunc(
115 testAccTestCheckExists("statuscake_test.google", &test),
116 resource.TestCheckResourceAttr("statuscake_test.google", "contact_id", altContactGroup),
117 ),
118 },
119 },
120 })
121}
122
58func testAccTestCheckExists(rn string, test *statuscake.Test) resource.TestCheckFunc { 123func testAccTestCheckExists(rn string, test *statuscake.Test) resource.TestCheckFunc {
59 return func(s *terraform.State) error { 124 return func(s *terraform.State) error {
60 rs, ok := s.RootModule().Resources[rn] 125 rs, ok := s.RootModule().Resources[rn]
@@ -113,3 +178,21 @@ resource "statuscake_test" "google" {
113 paused = true 178 paused = true
114} 179}
115` 180`
181
182var testAccTestConfig_contactGroup string = `` +
183 `resource "statuscake_test" "google" {
184 website_name = "google.com"
185 website_url = "www.google.com"
186 test_type = "HTTP"
187 check_rate = 300
188 contact_id = ` + os.Getenv("CONTACT_GROUP") + `
189 }`
190
191var testAccTestConfig_contactGroup_update string = `` +
192 `resource "statuscake_test" "google" {
193 website_name = "google.com"
194 website_url = "www.google.com"
195 test_type = "HTTP"
196 check_rate = 300
197 contact_id = ` + os.Getenv("ALT_CONTACT_GROUP") + `
198 }`