refactor: reduce some repeated code in tests (#368)

* refactor: Pull out common functionality of some tests

Mainly just in the destroy tests, condensing them to use the same functions where available. Some more reductions could be done, but I think this is a good balance between reducing repetition while keeping most functions readable and easy to understand.

* fix colliding test fail in credlib vault base
This commit is contained in:
Michael Milton authored and GitHub committed 2023-03-30 09:44:29 -04:00
1 parent 9be52c12b4
commit 16314193b9
18 files changed
+164 -469

No files matched your search

@@ -57,7 +57,7 @@ func TestAccManagedGroup(t *testing.T) {
var provider *schema.Provider
resource.Test(t, resource.TestCase{
ProviderFactories: providerFactories(&provider),
CheckDestroy: testAccCheckManagedGroupResourceDestroy(t, provider),
CheckDestroy: testAccCheckManagedGroupResourceDestroy(t, provider, baseManagedGroupType),
Steps: []resource.TestStep{
{
// test create
@@ -108,7 +108,14 @@ func testAccCheckManagedGroupResourceExists(testProvider *schema.Provider, name
}
}
func testAccCheckManagedGroupResourceDestroy(t *testing.T, testProvider *schema.Provider) resource.TestCheckFunc {
type managedGroupType string
const (
baseManagedGroupType managedGroupType = "boundary_managed_group"
ldapManagedGroupType managedGroupType = "boundary_managed_group_ldap"
)
func testAccCheckManagedGroupResourceDestroy(t *testing.T, testProvider *schema.Provider, typ managedGroupType) resource.TestCheckFunc {
return func(s *terraform.State) error {
if testProvider.Meta() == nil {
t.Fatal("got nil provider metadata")
@@ -118,7 +125,7 @@ func testAccCheckManagedGroupResourceDestroy(t *testing.T, testProvider *schema.
for _, rs := range s.RootModule().Resources {
switch rs.Type {
case "boundary_managed_group", "boundary_managed_group_ldap":
case string(typ):
grpClient := managedgroups.NewClient(md.client)
id := rs.Primary.ID