Skip to content
This repository has been archived by the owner on Jun 11, 2024. It is now read-only.

Commit

Permalink
Add acceptance test for default alert contact, fix some bugs.
Browse files Browse the repository at this point in the history
  • Loading branch information
Johan Bloemberg committed Apr 23, 2019
1 parent 613e608 commit 48b48a9
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 4 deletions.
3 changes: 1 addition & 2 deletions uptimerobot/api/alert_contact.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"errors"
"fmt"
"net/url"
"strconv"
)

// maximum pagination depth to allow (10*50=500 entries)
Expand Down Expand Up @@ -151,7 +150,7 @@ func (client UptimeRobotApiClient) CreateAlertContact(req AlertContactCreateRequ
// The difference made by it being a string is that a zero prefix to the ID // number is preserved. A zero prefixed alert contact ID is thus far only
// been observed on the default alert contact (created at account creation).
// https://github.com/louy/terraform-provider-uptimerobot/pull/21
return client.GetAlertContact(strconv.Itoa(alertcontact["id"].(int)))
return client.GetAlertContact(fmt.Sprintf("%.0f", alertcontact["id"].(float64)))
}

func (client UptimeRobotApiClient) DeleteAlertContact(id string) (err error) {
Expand Down
4 changes: 2 additions & 2 deletions uptimerobot/api/monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ func (client UptimeRobotApiClient) CreateMonitor(req MonitorCreateRequest) (m Mo
}
acStrings := make([]string, len(req.AlertContacts))
for k, v := range req.AlertContacts {
acStrings[k] = fmt.Sprintf("%d_%d_%d", v.ID, v.Threshold, v.Recurrence)
acStrings[k] = fmt.Sprintf("%s_%d_%d", v.ID, v.Threshold, v.Recurrence)
}
data.Add("alert_contacts", strings.Join(acStrings, "-"))

Expand Down Expand Up @@ -251,7 +251,7 @@ func (client UptimeRobotApiClient) UpdateMonitor(req MonitorUpdateRequest) (m Mo
}
acStrings := make([]string, len(req.AlertContacts))
for k, v := range req.AlertContacts {
acStrings[k] = fmt.Sprintf("%d_%d_%d", v.ID, v.Threshold, v.Recurrence)
acStrings[k] = fmt.Sprintf("%s_%d_%d", v.ID, v.Threshold, v.Recurrence)
}
data.Add("alert_contacts", strings.Join(acStrings, "-"))

Expand Down
45 changes: 45 additions & 0 deletions uptimerobot/resource_uptimerobot_monitor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,51 @@ func TestUptimeRobotDataResourceMonitor_http_auth_monitor(t *testing.T) {
})
}

func TestUptimeRobotDataResourceMonitor_default_alert_contact(t *testing.T) {
var FriendlyName = "TF Test: using the default alert contact"
var Type = "http"
var URL = "https://google.com"
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckMonitorDestroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: fmt.Sprintf(`
data "uptimerobot_account" "account" {}
data "uptimerobot_alert_contact" "default" {
friendly_name = "${data.uptimerobot_account.account.email}"
}
resource "uptimerobot_monitor" "test" {
friendly_name = "%s"
type = "%s"
url = "%s"
alert_contact {
id = "${data.uptimerobot_alert_contact.default.id}"
}
}
`, FriendlyName, Type, URL),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("uptimerobot_monitor.test", "friendly_name", FriendlyName),
resource.TestCheckResourceAttr("uptimerobot_monitor.test", "type", Type),
resource.TestCheckResourceAttr("uptimerobot_monitor.test", "url", URL),
resource.TestCheckResourceAttr("uptimerobot_monitor.test", "alert_contact.#", "1"),
resource.TestCheckResourceAttrSet("uptimerobot_monitor.test", "alert_contact.0.id"),
),
},
resource.TestStep{
ResourceName: "uptimerobot_monitor.test",
ImportState: true,
// uptimerobot doesn't support pulling alert_contact
// ImportStateVerify: true,
},
},
})
}

func testAccCheckMonitorDestroy(s *terraform.State) error {
client := testAccProvider.Meta().(uptimerobotapi.UptimeRobotApiClient)

Expand Down

0 comments on commit 48b48a9

Please sign in to comment.