diff options
-rw-r--r-- | resource_statuscaketest.go | 9 | ||||
-rw-r--r-- | resource_statuscaketest_test.go | 83 |
2 files changed, 92 insertions, 0 deletions
diff --git a/resource_statuscaketest.go b/resource_statuscaketest.go index 7f5ff67..d403848 100644 --- a/resource_statuscaketest.go +++ b/resource_statuscaketest.go | |||
@@ -33,6 +33,11 @@ func resourceStatusCakeTest() *schema.Resource { | |||
33 | Required: true, | 33 | Required: true, |
34 | }, | 34 | }, |
35 | 35 | ||
36 | "contact_id": &schema.Schema{ | ||
37 | Type: schema.TypeInt, | ||
38 | Optional: true, | ||
39 | }, | ||
40 | |||
36 | "check_rate": &schema.Schema{ | 41 | "check_rate": &schema.Schema{ |
37 | Type: schema.TypeInt, | 42 | Type: schema.TypeInt, |
38 | Optional: true, | 43 | Optional: true, |
@@ -65,6 +70,7 @@ func CreateTest(d *schema.ResourceData, meta interface{}) error { | |||
65 | WebsiteURL: d.Get("website_url").(string), | 70 | WebsiteURL: d.Get("website_url").(string), |
66 | TestType: d.Get("test_type").(string), | 71 | TestType: d.Get("test_type").(string), |
67 | CheckRate: d.Get("check_rate").(int), | 72 | CheckRate: d.Get("check_rate").(int), |
73 | ContactID: d.Get("contact_id").(int), | ||
68 | } | 74 | } |
69 | 75 | ||
70 | log.Printf("[DEBUG] Creating new StatusCake Test: %s", d.Get("website_name").(string)) | 76 | log.Printf("[DEBUG] Creating new StatusCake Test: %s", d.Get("website_name").(string)) |
@@ -142,6 +148,9 @@ func getStatusCakeTestInput(d *schema.ResourceData) *statuscake.Test { | |||
142 | if v, ok := d.GetOk("check_rate"); ok { | 148 | if v, ok := d.GetOk("check_rate"); ok { |
143 | test.CheckRate = v.(int) | 149 | test.CheckRate = v.(int) |
144 | } | 150 | } |
151 | if v, ok := d.GetOk("contact_id"); ok { | ||
152 | test.ContactID = v.(int) | ||
153 | } | ||
145 | if v, ok := d.GetOk("test_type"); ok { | 154 | if v, ok := d.GetOk("test_type"); ok { |
146 | test.TestType = v.(string) | 155 | test.TestType = v.(string) |
147 | } | 156 | } |
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 | ||
3 | import ( | 3 | import ( |
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. | ||
16 | func 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 | |||
13 | func TestAccStatusCake_basic(t *testing.T) { | 27 | func 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 | ||
72 | func 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 | |||
93 | func 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 | |||
58 | func testAccTestCheckExists(rn string, test *statuscake.Test) resource.TestCheckFunc { | 123 | func 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 | |||
182 | var 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 | |||
191 | var 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 | }` | ||