-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
21bc045
commit 8884d65
Showing
1 changed file
with
72 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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, | ||
}, | ||
), | ||
) | ||
} |