From 8884d65dfa846e264267d84961daa9de6acfd939 Mon Sep 17 00:00:00 2001 From: Deepak Gupta Date: Fri, 13 Dec 2024 17:43:46 -0500 Subject: [PATCH] add acceptance test --- cyral/internal/policy/policywizards_test.go | 72 +++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 cyral/internal/policy/policywizards_test.go diff --git a/cyral/internal/policy/policywizards_test.go b/cyral/internal/policy/policywizards_test.go new file mode 100644 index 00000000..b71f382f --- /dev/null +++ b/cyral/internal/policy/policywizards_test.go @@ -0,0 +1,72 @@ +package policyv2 + +import ( + "testing" + + "github.com/cyralinc/terraform-provider-cyral/cyral/provider" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" +) + +func TestAccPolicyWizardsDataSource(t *testing.T) { + dsName := "data.cyral_policy_wizards.wizard_list" + resource.ParallelTest(t, resource.TestCase{ + ProviderFactories: provider.ProviderFactories, + Steps: []resource.TestStep{ + { + Config: ` +data "cyral_policy_wizards" "wizard_list" { +} +`, + Check: checkAllWizards(dsName), + }, + { + Config: ` +data "cyral_policy_wizards" "wizard_list" { + wizard_id = "data-firewall" +} +`, + Check: checkOneWizard(dsName, "data-firewall"), + }, + }, + }) +} + +// checkAllWizards ensures that a few well known wizard ids are present in the +// datasource state. It does not attempt to make very exhaustive checks because +// wizard names, descriptions (and even the wizard list) is subject to change. +func checkAllWizards(dsName string) resource.TestCheckFunc { + return resource.ComposeTestCheckFunc( + resource.TestCheckTypeSetElemNestedAttrs( + dsName, "wizards.*", + map[string]string{ + "id": "data-firewall", + }, + ), + resource.TestCheckTypeSetElemNestedAttrs( + dsName, "wizards.*", + map[string]string{ + "id": "data-masking", + }, + ), + resource.TestCheckTypeSetElemNestedAttrs( + dsName, "wizards.*", + map[string]string{ + "id": "user-segmentation", + }, + ), + ) +} + +// checkOneWizard ensures that the data source state contains only one wizard +// with the given id. +func checkOneWizard(dsName, id string) resource.TestCheckFunc { + return resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr(dsName, "wizards.#", "1"), + resource.TestCheckTypeSetElemNestedAttrs( + dsName, "wizards.*", + map[string]string{ + "id": id, + }, + ), + ) +}