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

More tests #26

Merged
merged 5 commits into from
Apr 16, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions uptimerobot/api/monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ type Monitor struct {
HTTPUsername string `json:"http_username"`
HTTPPassword string `json:"http_password"`

CustomHTTPHeaders map[string]string
CustomHTTPHeaders map[string]string
}

func (client UptimeRobotApiClient) GetMonitor(id int) (m Monitor, err error) {
Expand Down Expand Up @@ -150,7 +150,7 @@ type MonitorCreateRequest struct {

AlertContacts []MonitorRequestAlertContact

CustomHTTPHeaders map[string]string
CustomHTTPHeaders map[string]string
}

func (client UptimeRobotApiClient) CreateMonitor(req MonitorCreateRequest) (m Monitor, err error) {
Expand Down Expand Up @@ -222,7 +222,7 @@ type MonitorUpdateRequest struct {

AlertContacts []MonitorRequestAlertContact

CustomHTTPHeaders map[string]string
CustomHTTPHeaders map[string]string
}

func (client UptimeRobotApiClient) UpdateMonitor(req MonitorUpdateRequest) (m Monitor, err error) {
Expand Down
44 changes: 44 additions & 0 deletions uptimerobot/resource_uptimerobot_alert_contact_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,50 @@ func TestUptimeRobotDataResourceAlertContact_email(t *testing.T) {
})
}

func TestUptimeRobotDataResourceAlertContact_update_email(t *testing.T) {
var email = "[email protected]"
var email2 = "[email protected]"
var friendlyName = "TF Test: Email"
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckAlertContactDestroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: fmt.Sprintf(`
resource "uptimerobot_alert_contact" "test" {
friendly_name = "%s"
type = "%s"
value = "%s"
}
`, friendlyName, "email", email),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("uptimerobot_alert_contact.test", "friendly_name", friendlyName),
resource.TestCheckResourceAttr("uptimerobot_alert_contact.test", "type", "email"),
resource.TestCheckResourceAttr("uptimerobot_alert_contact.test", "value", email),
),
},
resource.TestStep{
Config: fmt.Sprintf(`
resource "uptimerobot_alert_contact" "test" {
friendly_name = "%s"
type = "%s"
value = "%s"
}
`, friendlyName, "email", email2),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("uptimerobot_alert_contact.test", "value", email2),
),
},
resource.TestStep{
ResourceName: "uptimerobot_alert_contact.test",
ImportState: true,
ImportStateVerify: true,
},
},
})
}

func TestUptimeRobotDataResourceAlertContact_sms(t *testing.T) {
t.Skip("API seems to reject this")

Expand Down
2 changes: 1 addition & 1 deletion uptimerobot/resource_uptimerobot_monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ func resourceMonitor() *schema.Resource {
"custom_http_headers": {
Type: schema.TypeMap,
Optional: true,
},
},
// TODO - mwindows
// TODO - ignore_ssl_errors
},
Expand Down
152 changes: 97 additions & 55 deletions uptimerobot/resource_uptimerobot_monitor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ func TestUptimeRobotDataResourceMonitor_http_monitor(t *testing.T) {
var FriendlyName = "TF Test: http monitor"
var Type = "http"
var URL = "https://google.com"
var URL2 = "https://yahoo.com"
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
Expand All @@ -39,6 +40,81 @@ func TestUptimeRobotDataResourceMonitor_http_monitor(t *testing.T) {
ImportState: true,
ImportStateVerify: true,
},
resource.TestStep{
Config: fmt.Sprintf(`
resource "uptimerobot_monitor" "test" {
friendly_name = "%s"
type = "%s"
url = "%s"
}
`, FriendlyName, Type, URL2),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("uptimerobot_monitor.test", "url", URL2),
),
},
resource.TestStep{
ResourceName: "uptimerobot_monitor.test",
ImportState: true,
ImportStateVerify: true,
},
},
})
}

func TestUptimeRobotDataResourceMonitor_keyword_monitor(t *testing.T) {
var FriendlyName = "TF Test: keyword"
var Type = "keyword"
var URL = "https://google.com"
var KeywordType = "not exists"
var KeywordType2 = "exists"
var KeywordValue = "yahoo"
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckMonitorDestroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: fmt.Sprintf(`
resource "uptimerobot_monitor" "test" {
friendly_name = "%s"
type = "%s"
url = "%s"
keyword_type = "%s"
keyword_value = "%s"
}
`, FriendlyName, Type, URL, KeywordType, KeywordValue),
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", "keyword_type", KeywordType),
resource.TestCheckResourceAttr("uptimerobot_monitor.test", "keyword_value", KeywordValue),
),
},
resource.TestStep{
ResourceName: "uptimerobot_monitor.test",
ImportState: true,
ImportStateVerify: true,
},
resource.TestStep{
Config: fmt.Sprintf(`
resource "uptimerobot_monitor" "test" {
friendly_name = "%s"
type = "%s"
url = "%s"
keyword_type = "%s"
keyword_value = "%s"
}
`, FriendlyName, Type, URL, KeywordType2, KeywordValue),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("uptimerobot_monitor.test", "keyword_type", KeywordType2),
),
},
resource.TestStep{
ResourceName: "uptimerobot_monitor.test",
ImportState: true,
ImportStateVerify: true,
},
},
})
}
Expand All @@ -47,6 +123,7 @@ func TestUptimeRobotDataResourceMonitor_http_port_monitor(t *testing.T) {
var FriendlyName = "TF Test: http port monitor"
var Type = "port"
var URL = "google.com"
var URL2 = "yahoo.com"
var SubType = "http"
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Expand Down Expand Up @@ -74,6 +151,24 @@ func TestUptimeRobotDataResourceMonitor_http_port_monitor(t *testing.T) {
ImportState: true,
ImportStateVerify: true,
},
resource.TestStep{
Config: fmt.Sprintf(`
resource "uptimerobot_monitor" "test" {
friendly_name = "%s"
type = "%s"
url = "%s"
sub_type = "%s"
}
`, FriendlyName, Type, URL2, SubType),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("uptimerobot_monitor.test", "url", URL2),
),
},
resource.TestStep{
ResourceName: "uptimerobot_monitor.test",
ImportState: true,
ImportStateVerify: true,
},
},
})
}
Expand Down Expand Up @@ -154,8 +249,8 @@ func TestUptimeRobotDataResourceMonitor_custom_alert_contact_threshold_and_recur
),
},
resource.TestStep{
ResourceName: "uptimerobot_monitor.test",
ImportState: true,
ResourceName: "uptimerobot_monitor.test",
ImportState: true,
// uptimerobot doesn't support pulling alert_contact
// ImportStateVerify: true,
},
Expand Down Expand Up @@ -199,59 +294,6 @@ func TestUptimeRobotDataResourceMonitor_custom_http_headers(t *testing.T) {
})
}

func TestUptimeRobotDataResourceMonitor_change_url(t *testing.T) {
var FriendlyName = "TF Test: http monitor"
var Type = "http"
var URL = "https://google.com"
var URL2 = "https://google.co.uk"
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckMonitorDestroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: fmt.Sprintf(`
resource "uptimerobot_monitor" "test" {
friendly_name = "%s"
type = "%s"
url = "%s"
}
`, 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.TestStep{
ResourceName: "uptimerobot_monitor.test",
ImportState: true,
ImportStateVerify: true,
},
// Change url
resource.TestStep{
Config: fmt.Sprintf(`
resource "uptimerobot_monitor" "test" {
friendly_name = "%s"
type = "%s"
url = "%s"
}
`, FriendlyName, Type, URL2),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("uptimerobot_monitor.test", "friendly_name", FriendlyName),
resource.TestCheckResourceAttr("uptimerobot_monitor.test", "type", Type),
resource.TestCheckResourceAttr("uptimerobot_monitor.test", "url", URL2),
),
},
resource.TestStep{
ResourceName: "uptimerobot_monitor.test",
ImportState: true,
ImportStateVerify: true,
},
},
})
}

func TestUptimeRobotDataResourceMonitor_ping_monitor(t *testing.T) {
var FriendlyName = "TF Test: ping monitor"
var Type = "ping"
Expand Down
39 changes: 39 additions & 0 deletions uptimerobot/resource_uptimerobot_status_page_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,45 @@ func TestUptimeRobotDataResourceStatusPage_basic(t *testing.T) {
})
}

func TestUptimeRobotDataResourceStatusPage_update_name(t *testing.T) {
var friendlyName = "TF Test: Update name"
var friendlyName2 = "TF Test: Update name 2"
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckStatusPageDestroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: fmt.Sprintf(`
resource "uptimerobot_status_page" "test" {
friendly_name = "%s"
}
`, friendlyName),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("uptimerobot_status_page.test", "friendly_name", friendlyName),
resource.TestCheckResourceAttr("uptimerobot_status_page.test", "monitors.#", "1"),
resource.TestCheckResourceAttr("uptimerobot_status_page.test", "monitors.0", "0"),
),
},
resource.TestStep{
Config: fmt.Sprintf(`
resource "uptimerobot_status_page" "test" {
friendly_name = "%s"
}
`, friendlyName2),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("uptimerobot_status_page.test", "friendly_name", friendlyName2),
),
},
resource.TestStep{
ResourceName: "uptimerobot_status_page.test",
ImportState: true,
ImportStateVerify: true,
},
},
})
}

func TestUptimeRobotDataResourceStatusPage_custom_monitors(t *testing.T) {
var friendlyName = "TF Test: custom monitors"
resource.Test(t, resource.TestCase{
Expand Down