Skip to content

Commit

Permalink
re-factor a bit more
Browse files Browse the repository at this point in the history
  • Loading branch information
joaomper-TE committed Dec 12, 2023
1 parent 55f9ac0 commit 8aead26
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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/"

Expand Down
26 changes: 18 additions & 8 deletions thousandeyes/resource_ftp_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
{
Expand All @@ -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"),
},
},
}

Expand All @@ -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...),
},
},
})
Expand Down

0 comments on commit 8aead26

Please sign in to comment.