diff options
author | Rui Gonçalves <ruippeixotog@gmail.com> | 2016-12-11 19:41:49 +0000 |
---|---|---|
committer | Paul Stack <public@paulstack.co.uk> | 2016-12-11 19:41:49 +0000 |
commit | c07010769685fd6127e977d9ea7e891773fe75a0 (patch) | |
tree | 7b02d0fb988b794e4086675eb8a2a760007e998e | |
parent | 516886070835127727defe348567a0edfa138528 (diff) | |
download | terraform-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
-rw-r--r-- | resource_statuscaketest.go | 11 | ||||
-rw-r--r-- | resource_statuscaketest_test.go | 47 |
2 files changed, 54 insertions, 4 deletions
diff --git a/resource_statuscaketest.go b/resource_statuscaketest.go index 53b3059..08ace97 100644 --- a/resource_statuscaketest.go +++ b/resource_statuscaketest.go | |||
@@ -67,8 +67,11 @@ func CreateTest(d *schema.ResourceData, meta interface{}) error { | |||
67 | newTest := &statuscake.Test{ | 67 | newTest := &statuscake.Test{ |
68 | WebsiteName: d.Get("website_name").(string), | 68 | WebsiteName: d.Get("website_name").(string), |
69 | WebsiteURL: d.Get("website_url").(string), | 69 | WebsiteURL: d.Get("website_url").(string), |
70 | TestType: d.Get("test_type").(string), | ||
71 | CheckRate: d.Get("check_rate").(int), | 70 | CheckRate: d.Get("check_rate").(int), |
71 | TestType: d.Get("test_type").(string), | ||
72 | Paused: d.Get("paused").(bool), | ||
73 | Timeout: d.Get("timeout").(int), | ||
74 | ContactID: d.Get("contact_id").(int), | ||
72 | } | 75 | } |
73 | 76 | ||
74 | log.Printf("[DEBUG] Creating new StatusCake Test: %s", d.Get("website_name").(string)) | 77 | log.Printf("[DEBUG] Creating new StatusCake Test: %s", d.Get("website_name").(string)) |
@@ -124,7 +127,13 @@ func ReadTest(d *schema.ResourceData, meta interface{}) error { | |||
124 | if err != nil { | 127 | if err != nil { |
125 | return fmt.Errorf("Error Getting StatusCake Test Details for %s: Error: %s", d.Id(), err) | 128 | return fmt.Errorf("Error Getting StatusCake Test Details for %s: Error: %s", d.Id(), err) |
126 | } | 129 | } |
130 | d.Set("website_name", testResp.WebsiteName) | ||
131 | d.Set("website_url", testResp.WebsiteURL) | ||
127 | d.Set("check_rate", testResp.CheckRate) | 132 | d.Set("check_rate", testResp.CheckRate) |
133 | d.Set("test_type", testResp.TestType) | ||
134 | d.Set("paused", testResp.Paused) | ||
135 | d.Set("timeout", testResp.Timeout) | ||
136 | d.Set("contact_id", testResp.ContactID) | ||
128 | 137 | ||
129 | return nil | 138 | return nil |
130 | } | 139 | } |
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 | ||
89 | func 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 | |||
87 | func testAccTestCheckDestroy(test *statuscake.Test) resource.TestCheckFunc { | 129 | func 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 | ` |