diff options
Diffstat (limited to 'resource_statuscaketest_test.go')
-rw-r--r-- | resource_statuscaketest_test.go | 51 |
1 files changed, 48 insertions, 3 deletions
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 | ||
90 | func 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 | |||
87 | func testAccTestCheckDestroy(test *statuscake.Test) resource.TestCheckFunc { | 132 | func 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 | ` |