diff --git a/thousandeyes/acceptance_resources/ftp_server/alerts_enabled.tf b/thousandeyes/acceptance_resources/ftp_server/alerts_enabled.tf new file mode 100644 index 0000000..5925deb --- /dev/null +++ b/thousandeyes/acceptance_resources/ftp_server/alerts_enabled.tf @@ -0,0 +1,21 @@ +data "thousandeyes_agent" "test" { + agent_name = "Vancouver, Canada" +} + +resource "thousandeyes_ftp_server" "test" { + password = "test_password" + username = "test_username" + test_name = "Acceptance Test - FTP" + description = "description" + request_type = "Download" + ftp_time_limit = 10 + ftp_target_time = 1000 + interval = 900 + alerts_enabled = true + network_measurements = false + url = "ftp://speedtest.tele2.net/" + + agents { + agent_id = data.thousandeyes_agent.test.agent_id + } +} diff --git a/thousandeyes/acceptance_resources/ftp_server/alerts_enabled_multiple_alert_rules.tf b/thousandeyes/acceptance_resources/ftp_server/alerts_enabled_multiple_alert_rules.tf new file mode 100644 index 0000000..2ef442b --- /dev/null +++ b/thousandeyes/acceptance_resources/ftp_server/alerts_enabled_multiple_alert_rules.tf @@ -0,0 +1,32 @@ +data "thousandeyes_agent" "test" { + agent_name = "Vancouver, Canada" +} + +resource "thousandeyes_alert_rule" "alert-rule-ftp-test" { + rule_name = "API Team: (${var.environment}) Alert Slack" + alert_type = "HTTP Server" + expression = "((probDetail != \"\"))" + minimum_sources_pct = 80 + notify_on_clear = true + rounds_violating_out_of = 2 + rounds_violating_required = 2 + rounds_violating_mode = "ANY" +} + +resource "thousandeyes_ftp_server" "test" { + password = "test_password" + username = "test_username" + test_name = "Acceptance Test - FTP" + description = "description" + request_type = "Download" + ftp_time_limit = 10 + ftp_target_time = 1000 + interval = 900 + alerts_enabled = false + network_measurements = false + url = "ftp://speedtest.tele2.net/" + + agents { + agent_id = data.thousandeyes_agent.test.agent_id + } +} diff --git a/thousandeyes/acceptance_resources/ftp_server/basic.tf b/thousandeyes/acceptance_resources/ftp_server/basic.tf new file mode 100644 index 0000000..a330b3a --- /dev/null +++ b/thousandeyes/acceptance_resources/ftp_server/basic.tf @@ -0,0 +1,21 @@ +data "thousandeyes_agent" "test" { + agent_name = "Vancouver, Canada" +} + +resource "thousandeyes_ftp_server" "test" { + password = "test_password" + username = "test_username" + test_name = "Acceptance Test - FTP" + description = "description" + request_type = "Download" + ftp_time_limit = 10 + ftp_target_time = 1000 + interval = 900 + alerts_enabled = false + network_measurements = false + url = "ftp://speedtest.tele2.net/" + + agents { + agent_id = data.thousandeyes_agent.test.agent_id + } +} diff --git a/thousandeyes/resource_ftp_server_test.go b/thousandeyes/resource_ftp_server_test.go index bdddfc6..1fa888f 100644 --- a/thousandeyes/resource_ftp_server_test.go +++ b/thousandeyes/resource_ftp_server_test.go @@ -2,6 +2,7 @@ package thousandeyes import ( "fmt" + "os" "strconv" "testing" @@ -9,16 +10,46 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" ) -func TestAccThousandEyesFTPServer_basic(t *testing.T) { - testName := "tf-acc-test-ftp-server" - resourceName := "thousandeyes_ftp_server.test" +func TestAccThousandEyesFTPServer(t *testing.T) { + testCases := []struct { + name string + resourceFile string + resourceName string + checkDestroyFunction func(*terraform.State) error + }{ + { + name: "basic", + resourceFile: "acceptance_resources/ftp_server/basic.tf", + resourceName: "thousandeyes_ftp_server.test", + checkDestroyFunction: testAccCheckThousandEyesFTPServerDestroy, + }, + { + name: "alerts_enabled", + resourceFile: "acceptance_resources/ftp_server/alerts_enabled.tf", + resourceName: "thousandeyes_ftp_server.test", + checkDestroyFunction: testAccCheckThousandEyesFTPServerDestroy, + }, + } - resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - ProviderFactories: providerFactories, - CheckDestroy: testAccCheckThousandEyesFTPServerDestroy, - Steps: testAccCheckThousandEyesFTPServerSteps(testName, resourceName), - }) + for _, tc := range testCases { + t.Run(tc.name, func(t *testing.T) { + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: providerFactories, + CheckDestroy: tc.checkDestroyFunction, + Steps: []resource.TestStep{ + { + Config: testAccThousandEyesFTPServerConfig(tc.resourceFile), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr(tc.resourceName, "password", "test_password"), + resource.TestCheckResourceAttr(tc.resourceName, "username", "test_username"), + // Add more checks based on the resource attributes + ), + }, + }, + }) + }) + } } func testAccCheckThousandEyesFTPServerDestroy(s *terraform.State) error { @@ -37,10 +68,10 @@ func testAccCheckThousandEyesFTPServerDestroy(s *terraform.State) error { return nil } -func testAccCheckThousandEyesFTPServerSteps(testName, resourceName string) []resource.TestStep { +func testAccCheckThousandEyesFTPServerSteps(testResource, resourceName string) []resource.TestStep { return []resource.TestStep{ { - Config: testAccThousandEyesFTPServerConfig(testName), + Config: testAccThousandEyesFTPServerConfig(testResource), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr(resourceName, "password", "test_password"), resource.TestCheckResourceAttr(resourceName, "username", "test_username"), @@ -50,28 +81,10 @@ func testAccCheckThousandEyesFTPServerSteps(testName, resourceName string) []res } } -func testAccThousandEyesFTPServerConfig(testName string) string { - return fmt.Sprintf(` - data "thousandeyes_agent" "test"{ - agent_name = "Vancouver, Canada" - } - - resource "thousandeyes_ftp_server" "test" { - password = "test_password" - username = "test_username" - test_name = "Acceptance Test - FTP" - description = "description" - request_type = "Download" - ftp_time_limit = 10 - ftp_target_time = 1000 - interval = 900 - alerts_enabled = false - network_measurements = false - url = "ftp://speedtest.tele2.net/" - - agents { - agent_id = data.thousandeyes_agent.test.agent_id - } +func testAccThousandEyesFTPServerConfig(testResource string) string { + content, err := os.ReadFile(testResource) + if err != nil { + panic(err) } - `) + return string(content) }