Skip to content

Commit

Permalink
Keep resource in configuration for all steps so terraform will not de…
Browse files Browse the repository at this point in the history
…stroy them.
  • Loading branch information
denys-octopus committed Nov 18, 2024
1 parent a87bf21 commit 3eaa30b
Showing 1 changed file with 16 additions and 25 deletions.
41 changes: 16 additions & 25 deletions octopusdeploy_framework/datasource_workers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,47 +13,36 @@ import (
func TestAccDataSourceWorkers(t *testing.T) {
localName := acctest.RandStringFromCharSet(50, acctest.CharSetAlpha)
prefix := fmt.Sprintf("data.octopusdeploy_workers.%s", localName)
sshFilter := `communication_styles = ["Ssh"]`
listeningFilter := `communication_styles = ["TentaclePassive"]`

resource.Test(t, resource.TestCase{
ProtoV6ProviderFactories: ProtoV6ProviderFactories(),
PreCheck: func() { TestAccPreCheck(t) },
Steps: []resource.TestStep{
{
Config: createTestAccDataSourceWorkerResources(),
},
{
Config: createTestAccDataSourceWorkersEmpty(localName),
Config: createTestAccDataSourceWorkerResources(localName, ""),
Check: testAssertDataSourceWorkersEmpty(prefix),
},
{
Config: createTestAccDataSourceSSHWorkers(localName),
Config: createTestAccDataSourceWorkerResources(localName, sshFilter),
Check: testAssertDataSourceSSHWorkers(prefix),
},
{
Config: createTestAccDataSourceListeningWorkers(localName),
Config: createTestAccDataSourceWorkerResources(localName, listeningFilter),
Check: testAssertDataSourceListeningWorkers(prefix),
},
},
})
}

func createTestAccDataSourceWorkersEmpty(localName string) string {
return fmt.Sprintf(`data "octopusdeploy_workers" "%s" {}`, localName)
}

func testAssertDataSourceWorkersEmpty(prefix string) resource.TestCheckFunc {
return resource.ComposeTestCheckFunc(
testAssertWorkersDataSourceID(prefix),
resource.TestCheckResourceAttr(prefix, "workers.#", "2"),
)
}

func createTestAccDataSourceSSHWorkers(localName string) string {
return fmt.Sprintf(`data "octopusdeploy_workers" "%s" {
communication_styles = ["Ssh"]
}`, localName)
}

func testAssertDataSourceSSHWorkers(prefix string) resource.TestCheckFunc {
return resource.ComposeTestCheckFunc(
testAssertWorkersDataSourceID(prefix),
Expand All @@ -66,12 +55,6 @@ func testAssertDataSourceSSHWorkers(prefix string) resource.TestCheckFunc {
)
}

func createTestAccDataSourceListeningWorkers(localName string) string {
return fmt.Sprintf(`data "octopusdeploy_workers" "%s" {
communication_styles = ["TentaclePassive"]
}`, localName)
}

func testAssertDataSourceListeningWorkers(prefix string) resource.TestCheckFunc {
return resource.ComposeTestCheckFunc(
testAssertWorkersDataSourceID(prefix),
Expand All @@ -97,8 +80,9 @@ func testAssertWorkersDataSourceID(prefix string) resource.TestCheckFunc {
}
}

func createTestAccDataSourceWorkerResources() string {
return `resource "octopusdeploy_machine_policy" "policy_1" {
func createTestAccDataSourceWorkerResources(localName string, dataSourceFilter string) string {
return fmt.Sprintf(`
resource "octopusdeploy_machine_policy" "policy_1" {
name = "Machine Policy One"
}
Expand Down Expand Up @@ -132,5 +116,12 @@ func createTestAccDataSourceWorkerResources() string {
uri = "https://domain.test/"
thumbprint = "abcdef"
}
`
data "octopusdeploy_workers" "%s" {
%s
}
`,
localName,
dataSourceFilter,
)
}

0 comments on commit 3eaa30b

Please sign in to comment.