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 53b3059..389a7d6 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, |
@@ -69,6 +74,7 @@ func CreateTest(d *schema.ResourceData, meta interface{}) error { | |||
69 | WebsiteURL: d.Get("website_url").(string), | 74 | WebsiteURL: d.Get("website_url").(string), |
70 | TestType: d.Get("test_type").(string), | 75 | TestType: d.Get("test_type").(string), |
71 | CheckRate: d.Get("check_rate").(int), | 76 | CheckRate: d.Get("check_rate").(int), |
77 | ContactID: d.Get("contact_id").(int), | ||
72 | } | 78 | } |
73 | 79 | ||
74 | log.Printf("[DEBUG] Creating new StatusCake Test: %s", d.Get("website_name").(string)) | 80 | log.Printf("[DEBUG] Creating new StatusCake Test: %s", d.Get("website_name").(string)) |
@@ -146,6 +152,9 @@ func getStatusCakeTestInput(d *schema.ResourceData) *statuscake.Test { | |||
146 | if v, ok := d.GetOk("check_rate"); ok { | 152 | if v, ok := d.GetOk("check_rate"); ok { |
147 | test.CheckRate = v.(int) | 153 | test.CheckRate = v.(int) |
148 | } | 154 | } |
155 | if v, ok := d.GetOk("contact_id"); ok { | ||
156 | test.ContactID = v.(int) | ||
157 | } | ||
149 | if v, ok := d.GetOk("test_type"); ok { | 158 | if v, ok := d.GetOk("test_type"); ok { |
150 | test.TestType = v.(string) | 159 | test.TestType = v.(string) |
151 | } | 160 | } |
diff --git a/resource_statuscaketest_test.go b/resource_statuscaketest_test.go index bec1a45..236b790 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 | ||
@@ -56,6 +70,57 @@ func TestAccStatusCake_withUpdate(t *testing.T) { | |||
56 | }) | 70 | }) |
57 | } | 71 | } |
58 | 72 | ||
73 | func TestAccStatusCake_contactGroup_basic(t *testing.T) { | ||
74 | var test statuscake.Test | ||
75 | |||
76 | resource.Test(t, resource.TestCase{ | ||
77 | PreCheck: func() { | ||
78 | testAccPreCheck(t) | ||
79 | testAccContactGroupPreCheck(t, false) | ||
80 | }, | ||
81 | Providers: testAccProviders, | ||
82 | CheckDestroy: testAccTestCheckDestroy(&test), | ||
83 | Steps: []resource.TestStep{ | ||
84 | resource.TestStep{ | ||
85 | Config: testAccTestConfig_contactGroup, | ||
86 | Check: resource.ComposeTestCheckFunc( | ||
87 | testAccTestCheckExists("statuscake_test.google", &test), | ||
88 | ), | ||
89 | }, | ||
90 | }, | ||
91 | }) | ||
92 | } | ||
93 | |||
94 | func TestAccStatusCake_contactGroup_withUpdate(t *testing.T) { | ||
95 | var test statuscake.Test | ||
96 | var altContactGroup = os.Getenv("ALT_CONTACT_GROUP") | ||
97 | |||
98 | resource.Test(t, resource.TestCase{ | ||
99 | PreCheck: func() { | ||
100 | testAccPreCheck(t) | ||
101 | testAccContactGroupPreCheck(t, true) | ||
102 | }, | ||
103 | Providers: testAccProviders, | ||
104 | CheckDestroy: testAccTestCheckDestroy(&test), | ||
105 | Steps: []resource.TestStep{ | ||
106 | resource.TestStep{ | ||
107 | Config: testAccTestConfig_contactGroup, | ||
108 | Check: resource.ComposeTestCheckFunc( | ||
109 | testAccTestCheckExists("statuscake_test.google", &test), | ||
110 | ), | ||
111 | }, | ||
112 | // make sure to creat | ||
113 | resource.TestStep{ | ||
114 | Config: testAccTestConfig_contactGroup_update, | ||
115 | Check: resource.ComposeTestCheckFunc( | ||
116 | testAccTestCheckExists("statuscake_test.google", &test), | ||
117 | resource.TestCheckResourceAttr("statuscake_test.google", "contact_id", altContactGroup), | ||
118 | ), | ||
119 | }, | ||
120 | }, | ||
121 | }) | ||
122 | } | ||
123 | |||
59 | func testAccTestCheckExists(rn string, test *statuscake.Test) resource.TestCheckFunc { | 124 | func testAccTestCheckExists(rn string, test *statuscake.Test) resource.TestCheckFunc { |
60 | return func(s *terraform.State) error { | 125 | return func(s *terraform.State) error { |
61 | rs, ok := s.RootModule().Resources[rn] | 126 | rs, ok := s.RootModule().Resources[rn] |
@@ -116,3 +181,21 @@ resource "statuscake_test" "google" { | |||
116 | contact_id = 23456 | 181 | contact_id = 23456 |
117 | } | 182 | } |
118 | ` | 183 | ` |
184 | |||
185 | var testAccTestConfig_contactGroup string = `` + | ||
186 | `resource "statuscake_test" "google" { | ||
187 | website_name = "google.com" | ||
188 | website_url = "www.google.com" | ||
189 | test_type = "HTTP" | ||
190 | check_rate = 300 | ||
191 | contact_id = ` + os.Getenv("CONTACT_GROUP") + ` | ||
192 | }` | ||
193 | |||
194 | var testAccTestConfig_contactGroup_update string = `` + | ||
195 | `resource "statuscake_test" "google" { | ||
196 | website_name = "google.com" | ||
197 | website_url = "www.google.com" | ||
198 | test_type = "HTTP" | ||
199 | check_rate = 300 | ||
200 | contact_id = ` + os.Getenv("ALT_CONTACT_GROUP") + ` | ||
201 | }` | ||