aboutsummaryrefslogtreecommitdiffhomepage
path: root/resource_statuscaketest_test.go
diff options
context:
space:
mode:
authorRui Gonçalves <ruippeixotog@gmail.com>2016-12-11 19:41:49 +0000
committerPaul Stack <public@paulstack.co.uk>2016-12-11 19:41:49 +0000
commitc07010769685fd6127e977d9ea7e891773fe75a0 (patch)
tree7b02d0fb988b794e4086675eb8a2a760007e998e /resource_statuscaketest_test.go
parent516886070835127727defe348567a0edfa138528 (diff)
downloadterraform-provider-statuscake-c07010769685fd6127e977d9ea7e891773fe75a0.tar.gz
terraform-provider-statuscake-c07010769685fd6127e977d9ea7e891773fe75a0.tar.zst
terraform-provider-statuscake-c07010769685fd6127e977d9ea7e891773fe75a0.zip
provider/statuscake: fix StatusCake tests (#10660)
* Update vendored statuscake SDK * Set all attributes when upserting statuscake tests
Diffstat (limited to 'resource_statuscaketest_test.go')
-rw-r--r--resource_statuscaketest_test.go47
1 files changed, 44 insertions, 3 deletions
diff --git a/resource_statuscaketest_test.go b/resource_statuscaketest_test.go
index bec1a45..de30254 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,10 @@ 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"),
53 ), 55 ),
54 }, 56 },
55 }, 57 },
@@ -75,7 +77,7 @@ func testAccTestCheckExists(rn string, test *statuscake.Test) resource.TestCheck
75 77
76 gotTest, err := client.Tests().Detail(testId) 78 gotTest, err := client.Tests().Detail(testId)
77 if err != nil { 79 if err != nil {
78 return fmt.Errorf("error getting project: %s", err) 80 return fmt.Errorf("error getting test: %s", err)
79 } 81 }
80 82
81 *test = *gotTest 83 *test = *gotTest
@@ -84,6 +86,46 @@ func testAccTestCheckExists(rn string, test *statuscake.Test) resource.TestCheck
84 } 86 }
85} 87}
86 88
89func testAccTestCheckAttributes(rn string, test *statuscake.Test) resource.TestCheckFunc {
90 return func(s *terraform.State) error {
91 attrs := s.RootModule().Resources[rn].Primary.Attributes
92
93 check := func(key, stateValue, testValue string) error {
94 if testValue != stateValue {
95 return fmt.Errorf("different values for %s in state (%s) and in statuscake (%s)",
96 key, stateValue, testValue)
97 }
98 return nil
99 }
100
101 for key, value := range attrs {
102 var err error
103
104 switch key {
105 case "website_name":
106 err = check(key, value, test.WebsiteName)
107 case "website_url":
108 err = check(key, value, test.WebsiteURL)
109 case "check_rate":
110 err = check(key, value, strconv.Itoa(test.CheckRate))
111 case "test_type":
112 err = check(key, value, test.TestType)
113 case "paused":
114 err = check(key, value, strconv.FormatBool(test.Paused))
115 case "timeout":
116 err = check(key, value, strconv.Itoa(test.Timeout))
117 case "contact_id":
118 err = check(key, value, strconv.Itoa(test.ContactID))
119 }
120
121 if err != nil {
122 return err
123 }
124 }
125 return nil
126 }
127}
128
87func testAccTestCheckDestroy(test *statuscake.Test) resource.TestCheckFunc { 129func testAccTestCheckDestroy(test *statuscake.Test) resource.TestCheckFunc {
88 return func(s *terraform.State) error { 130 return func(s *terraform.State) error {
89 client := testAccProvider.Meta().(*statuscake.Client) 131 client := testAccProvider.Meta().(*statuscake.Client)
@@ -113,6 +155,5 @@ resource "statuscake_test" "google" {
113 test_type = "HTTP" 155 test_type = "HTTP"
114 check_rate = 500 156 check_rate = 500
115 paused = true 157 paused = true
116 contact_id = 23456
117} 158}
118` 159`