From 55d03796ac77ad24b1077e909517b96bb9af4dc4 Mon Sep 17 00:00:00 2001 From: Louay Alakkad Date: Tue, 16 Apr 2019 21:19:17 +0100 Subject: [PATCH 1/5] Add test for alert contact update --- ...resource_uptimerobot_alert_contact_test.go | 44 +++++++++++++++++++ .../resource_uptimerobot_monitor_test.go | 2 +- 2 files changed, 45 insertions(+), 1 deletion(-) diff --git a/uptimerobot/resource_uptimerobot_alert_contact_test.go b/uptimerobot/resource_uptimerobot_alert_contact_test.go index 8c00449..761bb72 100644 --- a/uptimerobot/resource_uptimerobot_alert_contact_test.go +++ b/uptimerobot/resource_uptimerobot_alert_contact_test.go @@ -42,6 +42,50 @@ func TestUptimeRobotDataResourceAlertContact_email(t *testing.T) { }) } +func TestUptimeRobotDataResourceAlertContact_update_email(t *testing.T) { + var email = "louay+tftest@alakkad.me" + var email2 = "louay+tftest2@alakkad.me" + 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") diff --git a/uptimerobot/resource_uptimerobot_monitor_test.go b/uptimerobot/resource_uptimerobot_monitor_test.go index 838ff0f..04c281f 100644 --- a/uptimerobot/resource_uptimerobot_monitor_test.go +++ b/uptimerobot/resource_uptimerobot_monitor_test.go @@ -200,7 +200,7 @@ func TestUptimeRobotDataResourceMonitor_custom_http_headers(t *testing.T) { } func TestUptimeRobotDataResourceMonitor_change_url(t *testing.T) { - var FriendlyName = "TF Test: http monitor" + var FriendlyName = "TF Test: change url" var Type = "http" var URL = "https://google.com" var URL2 = "https://google.co.uk" From 9829a5e91816f2ff93bfe65dbfd06c6b6695e3b1 Mon Sep 17 00:00:00 2001 From: Louay Alakkad Date: Tue, 16 Apr 2019 21:21:16 +0100 Subject: [PATCH 2/5] Add test for update status page --- .../resource_uptimerobot_status_page_test.go | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/uptimerobot/resource_uptimerobot_status_page_test.go b/uptimerobot/resource_uptimerobot_status_page_test.go index 9d228bd..5b38d61 100644 --- a/uptimerobot/resource_uptimerobot_status_page_test.go +++ b/uptimerobot/resource_uptimerobot_status_page_test.go @@ -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{ From cc8f147f2e931dbb01e459d559e3e03501abe844 Mon Sep 17 00:00:00 2001 From: Louay Alakkad Date: Tue, 16 Apr 2019 21:26:44 +0100 Subject: [PATCH 3/5] Add test for keyword monitor --- .../resource_uptimerobot_monitor_test.go | 42 ++++++++++++++++++- 1 file changed, 40 insertions(+), 2 deletions(-) diff --git a/uptimerobot/resource_uptimerobot_monitor_test.go b/uptimerobot/resource_uptimerobot_monitor_test.go index 04c281f..212148f 100644 --- a/uptimerobot/resource_uptimerobot_monitor_test.go +++ b/uptimerobot/resource_uptimerobot_monitor_test.go @@ -43,6 +43,44 @@ func TestUptimeRobotDataResourceMonitor_http_monitor(t *testing.T) { }) } +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 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, + }, + }, + }) +} + func TestUptimeRobotDataResourceMonitor_http_port_monitor(t *testing.T) { var FriendlyName = "TF Test: http port monitor" var Type = "port" @@ -154,8 +192,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, }, From 7ca8e230ef445c469c5b1841f7d81902fd94b540 Mon Sep 17 00:00:00 2001 From: Louay Alakkad Date: Tue, 16 Apr 2019 21:33:25 +0100 Subject: [PATCH 4/5] Add update test steps to different monitor tests --- .../resource_uptimerobot_monitor_test.go | 110 +++++++++--------- 1 file changed, 57 insertions(+), 53 deletions(-) diff --git a/uptimerobot/resource_uptimerobot_monitor_test.go b/uptimerobot/resource_uptimerobot_monitor_test.go index 212148f..ecc9877 100644 --- a/uptimerobot/resource_uptimerobot_monitor_test.go +++ b/uptimerobot/resource_uptimerobot_monitor_test.go @@ -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, @@ -39,6 +40,23 @@ 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, + }, }, }) } @@ -48,6 +66,7 @@ func TestUptimeRobotDataResourceMonitor_keyword_monitor(t *testing.T) { 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) }, @@ -77,6 +96,25 @@ func TestUptimeRobotDataResourceMonitor_keyword_monitor(t *testing.T) { 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, + }, }, }) } @@ -85,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) }, @@ -112,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, + }, }, }) } @@ -237,59 +294,6 @@ func TestUptimeRobotDataResourceMonitor_custom_http_headers(t *testing.T) { }) } -func TestUptimeRobotDataResourceMonitor_change_url(t *testing.T) { - var FriendlyName = "TF Test: change url" - 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" From 7ac9e99a40ddbb61765ce5d4e165c44ee1267836 Mon Sep 17 00:00:00 2001 From: Louay Alakkad Date: Tue, 16 Apr 2019 21:43:49 +0100 Subject: [PATCH 5/5] Go fmt --- uptimerobot/api/monitor.go | 6 +++--- uptimerobot/resource_uptimerobot_monitor.go | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/uptimerobot/api/monitor.go b/uptimerobot/api/monitor.go index 73ab266..269ca84 100644 --- a/uptimerobot/api/monitor.go +++ b/uptimerobot/api/monitor.go @@ -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) { @@ -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) { @@ -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) { diff --git a/uptimerobot/resource_uptimerobot_monitor.go b/uptimerobot/resource_uptimerobot_monitor.go index d9746fd..4d746e6 100644 --- a/uptimerobot/resource_uptimerobot_monitor.go +++ b/uptimerobot/resource_uptimerobot_monitor.go @@ -98,7 +98,7 @@ func resourceMonitor() *schema.Resource { "custom_http_headers": { Type: schema.TypeMap, Optional: true, - }, + }, // TODO - mwindows // TODO - ignore_ssl_errors },