From 8aead2682d09c1838c3b81f3aabee8b2e735252f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Mal=C3=A9s?= <85952626+joaomper-TE@users.noreply.github.com> Date: Tue, 12 Dec 2023 17:12:10 +0000 Subject: [PATCH] re-factor a bit more --- .../alerts_enabled_multiple_alert_rules.tf | 2 +- thousandeyes/resource_ftp_server_test.go | 26 +++++++++++++------ 2 files changed, 19 insertions(+), 9 deletions(-) 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 index 6ecfe99..82b61af 100644 --- a/thousandeyes/acceptance_resources/ftp_server/alerts_enabled_multiple_alert_rules.tf +++ b/thousandeyes/acceptance_resources/ftp_server/alerts_enabled_multiple_alert_rules.tf @@ -20,7 +20,7 @@ resource "thousandeyes_ftp_server" "test" { ftp_time_limit = 10 ftp_target_time = 1000 interval = 900 - alerts_enabled = false + alerts_enabled = true network_measurements = false url = "ftp://speedtest.tele2.net/" diff --git a/thousandeyes/resource_ftp_server_test.go b/thousandeyes/resource_ftp_server_test.go index f5eb2bf..44b2f40 100644 --- a/thousandeyes/resource_ftp_server_test.go +++ b/thousandeyes/resource_ftp_server_test.go @@ -9,28 +9,38 @@ import ( ) func TestAccThousandEyesFTPServer(t *testing.T) { + var ftpResourceName = "thousandeyes_ftp_server.test" testCases := []struct { name string resourceFile string resourceName string checkDestroyFunction func(*terraform.State) error + checkFunc []resource.TestCheckFunc }{ { name: "basic", resourceFile: "acceptance_resources/ftp_server/basic.tf", - resourceName: "thousandeyes_ftp_server.test", + resourceName: ftpResourceName, checkDestroyFunction: testAccCheckDefaultResourceDestroy, + checkFunc: []resource.TestCheckFunc{ + resource.TestCheckResourceAttr(ftpResourceName, "alerts_enabled", "false"), + resource.TestCheckResourceAttr(ftpResourceName, "alert_rules.#", "0"), + }, }, { name: "alerts_enabled", resourceFile: "acceptance_resources/ftp_server/alerts_enabled.tf", - resourceName: "thousandeyes_ftp_server.test", + resourceName: ftpResourceName, checkDestroyFunction: testAccCheckDefaultResourceDestroy, + checkFunc: []resource.TestCheckFunc{ + resource.TestCheckResourceAttr(ftpResourceName, "alerts_enabled", "true"), + resource.TestCheckResourceAttr(ftpResourceName, "alert_rules.#", "1"), + }, }, { name: "alerts_enabled_multiple_alert_rules", resourceFile: "acceptance_resources/ftp_server/alerts_enabled_multiple_alert_rules.tf", - resourceName: "thousandeyes_ftp_server.test", + resourceName: ftpResourceName, checkDestroyFunction: func(state *terraform.State) error { resourceList := []ResourceType{ { @@ -48,6 +58,10 @@ func TestAccThousandEyesFTPServer(t *testing.T) { } return testAccCheckResourceDestroy(resourceList, state) }, + checkFunc: []resource.TestCheckFunc{ + resource.TestCheckResourceAttr(ftpResourceName, "alerts_enabled", "true"), + resource.TestCheckResourceAttr(ftpResourceName, "alert_rules.#", "2"), + }, }, } @@ -60,11 +74,7 @@ func TestAccThousandEyesFTPServer(t *testing.T) { 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 - ), + Check: resource.ComposeTestCheckFunc(tc.checkFunc...), }, }, })