aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--resource_statuscaketest.go26
-rw-r--r--resource_statuscaketest_test.go51
2 files changed, 70 insertions, 7 deletions
diff --git a/resource_statuscaketest.go b/resource_statuscaketest.go
index a1d7354..0cdc76d 100644
--- a/resource_statuscaketest.go
+++ b/resource_statuscaketest.go
@@ -58,6 +58,10 @@ func resourceStatusCakeTest() *schema.Resource {
58 Type: schema.TypeInt, 58 Type: schema.TypeInt,
59 Computed: true, 59 Computed: true,
60 }, 60 },
61 "confirmations": &schema.Schema{
62 Type: schema.TypeInt,
63 Optional: true,
64 },
61 }, 65 },
62 } 66 }
63} 67}
@@ -66,10 +70,14 @@ func CreateTest(d *schema.ResourceData, meta interface{}) error {
66 client := meta.(*statuscake.Client) 70 client := meta.(*statuscake.Client)
67 71
68 newTest := &statuscake.Test{ 72 newTest := &statuscake.Test{
69 WebsiteName: d.Get("website_name").(string), 73 WebsiteName: d.Get("website_name").(string),
70 WebsiteURL: d.Get("website_url").(string), 74 WebsiteURL: d.Get("website_url").(string),
71 TestType: d.Get("test_type").(string), 75 CheckRate: d.Get("check_rate").(int),
72 CheckRate: d.Get("check_rate").(int), 76 TestType: d.Get("test_type").(string),
77 Paused: d.Get("paused").(bool),
78 Timeout: d.Get("timeout").(int),
79 ContactID: d.Get("contact_id").(int),
80 Confirmation: d.Get("confirmations").(int),
73 } 81 }
74 82
75 log.Printf("[DEBUG] Creating new StatusCake Test: %s", d.Get("website_name").(string)) 83 log.Printf("[DEBUG] Creating new StatusCake Test: %s", d.Get("website_name").(string))
@@ -125,7 +133,14 @@ func ReadTest(d *schema.ResourceData, meta interface{}) error {
125 if err != nil { 133 if err != nil {
126 return fmt.Errorf("Error Getting StatusCake Test Details for %s: Error: %s", d.Id(), err) 134 return fmt.Errorf("Error Getting StatusCake Test Details for %s: Error: %s", d.Id(), err)
127 } 135 }
136 d.Set("website_name", testResp.WebsiteName)
137 d.Set("website_url", testResp.WebsiteURL)
128 d.Set("check_rate", testResp.CheckRate) 138 d.Set("check_rate", testResp.CheckRate)
139 d.Set("test_type", testResp.TestType)
140 d.Set("paused", testResp.Paused)
141 d.Set("timeout", testResp.Timeout)
142 d.Set("contact_id", testResp.ContactID)
143 d.Set("confirmations", testResp.Confirmation)
129 144
130 return nil 145 return nil
131} 146}
@@ -162,5 +177,8 @@ func getStatusCakeTestInput(d *schema.ResourceData) *statuscake.Test {
162 if v, ok := d.GetOk("contact_id"); ok { 177 if v, ok := d.GetOk("contact_id"); ok {
163 test.ContactID = v.(int) 178 test.ContactID = v.(int)
164 } 179 }
180 if v, ok := d.GetOk("confirmations"); ok {
181 test.Confirmation = v.(int)
182 }
165 return test 183 return test
166} 184}
diff --git a/resource_statuscaketest_test.go b/resource_statuscaketest_test.go
index bec1a45..ac3cc92 100644
--- a/resource_statuscaketest_test.go
+++ b/resource_statuscaketest_test.go
@@ -22,6 +22,7 @@ func TestAccStatusCake_basic(t *testing.T) {
22 Config: testAccTestConfig_basic, 22 Config: testAccTestConfig_basic,
23 Check: resource.ComposeTestCheckFunc( 23 Check: resource.ComposeTestCheckFunc(
24 testAccTestCheckExists("statuscake_test.google", &test), 24 testAccTestCheckExists("statuscake_test.google", &test),
25 testAccTestCheckAttributes("statuscake_test.google", &test),
25 ), 26 ),
26 }, 27 },
27 }, 28 },
@@ -47,9 +48,11 @@ func TestAccStatusCake_withUpdate(t *testing.T) {
47 Config: testAccTestConfig_update, 48 Config: testAccTestConfig_update,
48 Check: resource.ComposeTestCheckFunc( 49 Check: resource.ComposeTestCheckFunc(
49 testAccTestCheckExists("statuscake_test.google", &test), 50 testAccTestCheckExists("statuscake_test.google", &test),
51 testAccTestCheckAttributes("statuscake_test.google", &test),
50 resource.TestCheckResourceAttr("statuscake_test.google", "check_rate", "500"), 52 resource.TestCheckResourceAttr("statuscake_test.google", "check_rate", "500"),
51 resource.TestCheckResourceAttr("statuscake_test.google", "paused", "true"), 53 resource.TestCheckResourceAttr("statuscake_test.google", "paused", "true"),
52 resource.TestCheckResourceAttr("statuscake_test.google", "contact_id", "23456"), 54 resource.TestCheckResourceAttr("statuscake_test.google", "contact_id", "0"),
55 resource.TestCheckResourceAttr("statuscake_test.google", "confirmations", "0"),
53 ), 56 ),
54 }, 57 },
55 }, 58 },
@@ -75,7 +78,7 @@ func testAccTestCheckExists(rn string, test *statuscake.Test) resource.TestCheck
75 78
76 gotTest, err := client.Tests().Detail(testId) 79 gotTest, err := client.Tests().Detail(testId)
77 if err != nil { 80 if err != nil {
78 return fmt.Errorf("error getting project: %s", err) 81 return fmt.Errorf("error getting test: %s", err)
79 } 82 }
80 83
81 *test = *gotTest 84 *test = *gotTest
@@ -84,6 +87,48 @@ func testAccTestCheckExists(rn string, test *statuscake.Test) resource.TestCheck
84 } 87 }
85} 88}
86 89
90func testAccTestCheckAttributes(rn string, test *statuscake.Test) resource.TestCheckFunc {
91 return func(s *terraform.State) error {
92 attrs := s.RootModule().Resources[rn].Primary.Attributes
93
94 check := func(key, stateValue, testValue string) error {
95 if testValue != stateValue {
96 return fmt.Errorf("different values for %s in state (%s) and in statuscake (%s)",
97 key, stateValue, testValue)
98 }
99 return nil
100 }
101
102 for key, value := range attrs {
103 var err error
104
105 switch key {
106 case "website_name":
107 err = check(key, value, test.WebsiteName)
108 case "website_url":
109 err = check(key, value, test.WebsiteURL)
110 case "check_rate":
111 err = check(key, value, strconv.Itoa(test.CheckRate))
112 case "test_type":
113 err = check(key, value, test.TestType)
114 case "paused":
115 err = check(key, value, strconv.FormatBool(test.Paused))
116 case "timeout":
117 err = check(key, value, strconv.Itoa(test.Timeout))
118 case "contact_id":
119 err = check(key, value, strconv.Itoa(test.ContactID))
120 case "confirmations":
121 err = check(key, value, strconv.Itoa(test.Confirmation))
122 }
123
124 if err != nil {
125 return err
126 }
127 }
128 return nil
129 }
130}
131
87func testAccTestCheckDestroy(test *statuscake.Test) resource.TestCheckFunc { 132func testAccTestCheckDestroy(test *statuscake.Test) resource.TestCheckFunc {
88 return func(s *terraform.State) error { 133 return func(s *terraform.State) error {
89 client := testAccProvider.Meta().(*statuscake.Client) 134 client := testAccProvider.Meta().(*statuscake.Client)
@@ -103,6 +148,7 @@ resource "statuscake_test" "google" {
103 test_type = "HTTP" 148 test_type = "HTTP"
104 check_rate = 300 149 check_rate = 300
105 contact_id = 12345 150 contact_id = 12345
151 confirmations = 1
106} 152}
107` 153`
108 154
@@ -113,6 +159,5 @@ resource "statuscake_test" "google" {
113 test_type = "HTTP" 159 test_type = "HTTP"
114 check_rate = 500 160 check_rate = 500
115 paused = true 161 paused = true
116 contact_id = 23456
117} 162}
118` 163`