Skip to content

Commit dc80fab

Browse files
authored
test: Refactors custom DB role tests and adds documentation for empty database (#3294)
* refactor: Remove redundant TestAccConfigRSCustomDBRoles_MultipleResources test (running the same test 5 times, not using multiple resources as the name says) * test: Remove duplication and add check for empty database_name * refactor: Use data source also in resource test * refactor: Enhance custom DB role tests with plural data source checks * feat: Add PluralResultCheck function * doc: Clarify database_name usage in custom DB role documentation * refactor: Remove redundant variable declaration and update comment for PluralResultCheck * refactor: Remove nil check for results in findResultsMatch function
1 parent b6effa3 commit dc80fab

10 files changed

+268
-246
lines changed

docs/data-sources/custom_db_role.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ Each object in the actions array represents an individual privilege action grant
5353

5454
* `resources.#.collection_name` - (Optional) Collection on which the action is granted. If this value is an empty string, the action is granted on all collections within the database specified in the actions.resources.db field.
5555

56-
* `resources.#.database_name` Database on which the action is granted.
56+
* `resources.#.database_name` Database on which the action is granted. The empty string ("") allows an action on all databases.
5757

5858
* `resources.#.cluster` (Optional) Set to true to indicate that the action is granted on the cluster resource.
5959

docs/data-sources/custom_db_roles.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ Each object in the actions array represents an individual privilege action grant
4949

5050
* `resources.#.collection_name` - (Optional) Collection on which the action is granted. If this value is an empty string, the action is granted on all collections within the database specified in the actions.resources.db field.
5151

52-
* `resources.#.database_name` Database on which the action is granted.
52+
* `resources.#.database_name` Database on which the action is granted. The empty string ("") allows an action on all databases.
5353

5454
* `resources.#.cluster` (Optional) Set to true to indicate that the action is granted on the cluster resource.
5555

docs/resources/custom_db_role.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ resource "mongodbatlas_custom_db_role" "test_role" {
1818
action = "UPDATE"
1919
resources {
2020
collection_name = ""
21-
database_name = "anyDatabase"
21+
database_name = "anyDatabase" # use the empty string ("") to allow an action on all databases.
2222
}
2323
}
2424
actions {
@@ -123,7 +123,7 @@ Each object in the actions array represents an individual privilege action grant
123123

124124
-> **NOTE** This field is mutually exclusive with the `actions.resources.cluster` field.
125125

126-
* `resources.#.database_name` Database on which the action is granted.
126+
* `resources.#.database_name` Database on which the action is granted. Use the empty string ("") to allow an action on all databases.
127127

128128
-> **NOTE** This field is mutually exclusive with the `actions.resources.cluster` field.
129129

internal/service/customdbrole/data_source_custom_db_role_test.go

Lines changed: 0 additions & 73 deletions
This file was deleted.

internal/service/customdbrole/data_source_custom_db_roles_test.go

Lines changed: 0 additions & 71 deletions
This file was deleted.
Lines changed: 1 addition & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,11 @@
11
package customdbrole_test
22

33
import (
4-
"os"
54
"testing"
65

7-
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
8-
"github.com/mongodb/terraform-provider-mongodbatlas/internal/testutil/acc"
96
"github.com/mongodb/terraform-provider-mongodbatlas/internal/testutil/mig"
107
)
118

129
func TestMigConfigCustomDBRoles_Basic(t *testing.T) {
13-
var (
14-
orgID = os.Getenv("MONGODB_ATLAS_ORG_ID")
15-
projectName = acc.RandomProjectName()
16-
roleName = acc.RandomName()
17-
databaseName = acc.RandomClusterName()
18-
config = configBasic(orgID, projectName, roleName, "INSERT", databaseName)
19-
)
20-
21-
resource.ParallelTest(t, resource.TestCase{
22-
PreCheck: func() { mig.PreCheckBasic(t) },
23-
CheckDestroy: checkDestroy,
24-
Steps: []resource.TestStep{
25-
{
26-
ExternalProviders: mig.ExternalProviders(),
27-
Config: config,
28-
Check: resource.ComposeAggregateTestCheckFunc(
29-
checkExists(resourceName),
30-
resource.TestCheckResourceAttrSet(resourceName, "project_id"),
31-
resource.TestCheckResourceAttr(resourceName, "role_name", roleName),
32-
resource.TestCheckResourceAttr(resourceName, "actions.#", "1"),
33-
resource.TestCheckResourceAttr(resourceName, "actions.0.action", "INSERT"),
34-
resource.TestCheckResourceAttr(resourceName, "actions.0.resources.#", "1"),
35-
),
36-
},
37-
mig.TestStepCheckEmptyPlan(config),
38-
},
39-
})
10+
mig.CreateAndRunTest(t, basicTestCase(t))
4011
}

0 commit comments

Comments
 (0)