diff --git a/octopusdeploy_framework/datasource_workers_test.go b/octopusdeploy_framework/datasource_workers_test.go index 260910b4..07c7fcb6 100644 --- a/octopusdeploy_framework/datasource_workers_test.go +++ b/octopusdeploy_framework/datasource_workers_test.go @@ -13,34 +13,29 @@ 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), @@ -48,12 +43,6 @@ func testAssertDataSourceWorkersEmpty(prefix string) resource.TestCheckFunc { ) } -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), @@ -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), @@ -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" } @@ -132,5 +116,12 @@ func createTestAccDataSourceWorkerResources() string { uri = "https://domain.test/" thumbprint = "abcdef" } -` + + data "octopusdeploy_workers" "%s" { + %s + } + `, + localName, + dataSourceFilter, + ) }