provider/statuscake: fix StatusCake tests (#10660)
* Update vendored statuscake SDK * Set all attributes when upserting statuscake tests
This commit is contained in:
parent
c02b2471d6
commit
5016a56fd4
|
@ -67,8 +67,11 @@ func CreateTest(d *schema.ResourceData, meta interface{}) error {
|
||||||
newTest := &statuscake.Test{
|
newTest := &statuscake.Test{
|
||||||
WebsiteName: d.Get("website_name").(string),
|
WebsiteName: d.Get("website_name").(string),
|
||||||
WebsiteURL: d.Get("website_url").(string),
|
WebsiteURL: d.Get("website_url").(string),
|
||||||
TestType: d.Get("test_type").(string),
|
|
||||||
CheckRate: d.Get("check_rate").(int),
|
CheckRate: d.Get("check_rate").(int),
|
||||||
|
TestType: d.Get("test_type").(string),
|
||||||
|
Paused: d.Get("paused").(bool),
|
||||||
|
Timeout: d.Get("timeout").(int),
|
||||||
|
ContactID: d.Get("contact_id").(int),
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Printf("[DEBUG] Creating new StatusCake Test: %s", d.Get("website_name").(string))
|
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 {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("Error Getting StatusCake Test Details for %s: Error: %s", d.Id(), err)
|
return fmt.Errorf("Error Getting StatusCake Test Details for %s: Error: %s", d.Id(), err)
|
||||||
}
|
}
|
||||||
|
d.Set("website_name", testResp.WebsiteName)
|
||||||
|
d.Set("website_url", testResp.WebsiteURL)
|
||||||
d.Set("check_rate", testResp.CheckRate)
|
d.Set("check_rate", testResp.CheckRate)
|
||||||
|
d.Set("test_type", testResp.TestType)
|
||||||
|
d.Set("paused", testResp.Paused)
|
||||||
|
d.Set("timeout", testResp.Timeout)
|
||||||
|
d.Set("contact_id", testResp.ContactID)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,6 +22,7 @@ func TestAccStatusCake_basic(t *testing.T) {
|
||||||
Config: testAccTestConfig_basic,
|
Config: testAccTestConfig_basic,
|
||||||
Check: resource.ComposeTestCheckFunc(
|
Check: resource.ComposeTestCheckFunc(
|
||||||
testAccTestCheckExists("statuscake_test.google", &test),
|
testAccTestCheckExists("statuscake_test.google", &test),
|
||||||
|
testAccTestCheckAttributes("statuscake_test.google", &test),
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -47,9 +48,10 @@ func TestAccStatusCake_withUpdate(t *testing.T) {
|
||||||
Config: testAccTestConfig_update,
|
Config: testAccTestConfig_update,
|
||||||
Check: resource.ComposeTestCheckFunc(
|
Check: resource.ComposeTestCheckFunc(
|
||||||
testAccTestCheckExists("statuscake_test.google", &test),
|
testAccTestCheckExists("statuscake_test.google", &test),
|
||||||
|
testAccTestCheckAttributes("statuscake_test.google", &test),
|
||||||
resource.TestCheckResourceAttr("statuscake_test.google", "check_rate", "500"),
|
resource.TestCheckResourceAttr("statuscake_test.google", "check_rate", "500"),
|
||||||
resource.TestCheckResourceAttr("statuscake_test.google", "paused", "true"),
|
resource.TestCheckResourceAttr("statuscake_test.google", "paused", "true"),
|
||||||
resource.TestCheckResourceAttr("statuscake_test.google", "contact_id", "23456"),
|
resource.TestCheckResourceAttr("statuscake_test.google", "contact_id", "0"),
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -75,7 +77,7 @@ func testAccTestCheckExists(rn string, test *statuscake.Test) resource.TestCheck
|
||||||
|
|
||||||
gotTest, err := client.Tests().Detail(testId)
|
gotTest, err := client.Tests().Detail(testId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("error getting project: %s", err)
|
return fmt.Errorf("error getting test: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
*test = *gotTest
|
*test = *gotTest
|
||||||
|
@ -84,6 +86,46 @@ func testAccTestCheckExists(rn string, test *statuscake.Test) resource.TestCheck
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func testAccTestCheckAttributes(rn string, test *statuscake.Test) resource.TestCheckFunc {
|
||||||
|
return func(s *terraform.State) error {
|
||||||
|
attrs := s.RootModule().Resources[rn].Primary.Attributes
|
||||||
|
|
||||||
|
check := func(key, stateValue, testValue string) error {
|
||||||
|
if testValue != stateValue {
|
||||||
|
return fmt.Errorf("different values for %s in state (%s) and in statuscake (%s)",
|
||||||
|
key, stateValue, testValue)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
for key, value := range attrs {
|
||||||
|
var err error
|
||||||
|
|
||||||
|
switch key {
|
||||||
|
case "website_name":
|
||||||
|
err = check(key, value, test.WebsiteName)
|
||||||
|
case "website_url":
|
||||||
|
err = check(key, value, test.WebsiteURL)
|
||||||
|
case "check_rate":
|
||||||
|
err = check(key, value, strconv.Itoa(test.CheckRate))
|
||||||
|
case "test_type":
|
||||||
|
err = check(key, value, test.TestType)
|
||||||
|
case "paused":
|
||||||
|
err = check(key, value, strconv.FormatBool(test.Paused))
|
||||||
|
case "timeout":
|
||||||
|
err = check(key, value, strconv.Itoa(test.Timeout))
|
||||||
|
case "contact_id":
|
||||||
|
err = check(key, value, strconv.Itoa(test.ContactID))
|
||||||
|
}
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func testAccTestCheckDestroy(test *statuscake.Test) resource.TestCheckFunc {
|
func testAccTestCheckDestroy(test *statuscake.Test) resource.TestCheckFunc {
|
||||||
return func(s *terraform.State) error {
|
return func(s *terraform.State) error {
|
||||||
client := testAccProvider.Meta().(*statuscake.Client)
|
client := testAccProvider.Meta().(*statuscake.Client)
|
||||||
|
@ -113,6 +155,5 @@ resource "statuscake_test" "google" {
|
||||||
test_type = "HTTP"
|
test_type = "HTTP"
|
||||||
check_rate = 500
|
check_rate = 500
|
||||||
paused = true
|
paused = true
|
||||||
contact_id = 23456
|
|
||||||
}
|
}
|
||||||
`
|
`
|
||||||
|
|
|
@ -28,7 +28,7 @@ type Test struct {
|
||||||
Port int `json:"Port" querystring:"Port"`
|
Port int `json:"Port" querystring:"Port"`
|
||||||
|
|
||||||
// Contact group ID - will return int of contact group used else 0
|
// Contact group ID - will return int of contact group used else 0
|
||||||
ContactID int `json:"ContactID"`
|
ContactID int `json:"ContactID" querystring:"ContactGroup"`
|
||||||
|
|
||||||
// Current status at last test
|
// Current status at last test
|
||||||
Status string `json:"Status"`
|
Status string `json:"Status"`
|
||||||
|
|
|
@ -306,8 +306,10 @@
|
||||||
"revision": "edd0930276e7f1a5f2cf3e7835b5dc42a3217669"
|
"revision": "edd0930276e7f1a5f2cf3e7835b5dc42a3217669"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
"checksumSHA1": "jZHdtVQsg/9NeRqbxwy63OSbLl8=",
|
||||||
"path": "github.com/DreamItGetIT/statuscake",
|
"path": "github.com/DreamItGetIT/statuscake",
|
||||||
"revision": "8cbe86575f00210a6df2c19cb2f59b00cd181de3"
|
"revision": "9bfac395790f4d221cb5088c5c411f0ba8ba5f23",
|
||||||
|
"revisionTime": "2016-12-01T15:35:21Z"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"path": "github.com/Ensighten/udnssdk",
|
"path": "github.com/Ensighten/udnssdk",
|
||||||
|
|
Loading…
Reference in New Issue