-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
kubernetes clusters pagination support
- Loading branch information
1 parent
9eaea47
commit 0b4170c
Showing
4 changed files
with
163 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
84 changes: 84 additions & 0 deletions
84
internal/acceptance/data_source_kubernetes_clusters_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
package acceptance | ||
|
||
import ( | ||
"fmt" | ||
"regexp" | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform-plugin-testing/helper/resource" | ||
) | ||
|
||
// TestAccDatasourceWizKubernetesClusters_basic tests the basic functionality of the datasource | ||
// wiz_kubernetes_clusters. The assumption is that at least two clusters exist in the Wiz tenant in order | ||
// to validate pagination functionality | ||
func TestAccDatasourceWizKubernetesClusters_basic(t *testing.T) { | ||
resource.UnitTest(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
ProviderFactories: providerFactories, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccDatasourceWizKubernetesClustersBasic(1), | ||
Check: resource.ComposeTestCheckFunc( | ||
resource.TestMatchResourceAttr( | ||
// check first kubernetes cluster has an id that matches the UUID regex | ||
"data.wiz_kubernetes_clusters.foo", | ||
"kubernetes_clusters.0.id", | ||
regexp.MustCompile(UUIDPattern), | ||
), | ||
resource.TestMatchResourceAttr( | ||
// check first kubernetes cluster has a name that is set to a non-empty string | ||
"data.wiz_kubernetes_clusters.foo", | ||
"kubernetes_clusters.0.name", | ||
regexp.MustCompile(`\w`), | ||
), | ||
resource.TestMatchResourceAttr( | ||
// check cloud_account_block has id that matches the UUID regex | ||
"data.wiz_kubernetes_clusters.foo", | ||
"kubernetes_clusters.0.cloud_account.0.id", | ||
regexp.MustCompile(UUIDPattern), | ||
), | ||
resource.TestMatchResourceAttr( | ||
// check cloud_account_block has external_id set to a non-empty string, different cloud providers have different formats | ||
"data.wiz_kubernetes_clusters.foo", | ||
"kubernetes_clusters.0.cloud_account.0.external_id", | ||
regexp.MustCompile(`\w`), | ||
), | ||
resource.TestMatchResourceAttr( | ||
// check cloud_account_block has name set to a non-empty string | ||
"data.wiz_kubernetes_clusters.foo", | ||
"kubernetes_clusters.0.cloud_account.0.name", | ||
regexp.MustCompile(`\w`), | ||
), | ||
resource.TestMatchResourceAttr( | ||
// check cloud_account_block has cloud_provider set to a non-empty string | ||
"data.wiz_kubernetes_clusters.foo", | ||
"kubernetes_clusters.0.cloud_account.0.cloud_provider", | ||
regexp.MustCompile(`\w`), | ||
), | ||
), | ||
}, | ||
{ | ||
Config: testAccDatasourceWizKubernetesClustersBasic(2), | ||
Check: resource.ComposeTestCheckFunc( | ||
resource.TestMatchResourceAttr( | ||
// check that the second kubernetes cluster has an id that matches the UUID regex | ||
"data.wiz_kubernetes_clusters.foo", | ||
"kubernetes_clusters.1.id", | ||
regexp.MustCompile(`\w`), | ||
), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testAccDatasourceWizKubernetesClustersBasic(maxPages int) string { | ||
return fmt.Sprintf(` | ||
data "wiz_kubernetes_clusters" "foo" { | ||
first = 1 | ||
max_pages = %d | ||
search = "" | ||
} | ||
`, maxPages) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters