Skip to content

Commit 79a8e8f

Browse files
authored
test: Adds value check of roles in mongodbatlas_api_key_project_assignment resource (#3518)
* add check of roles * set check * remove unnecessary param * ConfigStateChecks
1 parent 9b8b258 commit 79a8e8f

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

internal/service/apikeyprojectassignment/resource_test.go

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@ import (
77
"testing"
88

99
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
10+
"github.com/hashicorp/terraform-plugin-testing/knownvalue"
11+
"github.com/hashicorp/terraform-plugin-testing/statecheck"
1012
"github.com/hashicorp/terraform-plugin-testing/terraform"
13+
"github.com/hashicorp/terraform-plugin-testing/tfjsonpath"
1114
"github.com/mongodb/terraform-provider-mongodbatlas/internal/common/conversion"
1215
"github.com/mongodb/terraform-provider-mongodbatlas/internal/common/validate"
1316
"github.com/mongodb/terraform-provider-mongodbatlas/internal/testutil/acc"
@@ -35,10 +38,28 @@ func TestAccApiKeyProjectAssignmentRS_basic(t *testing.T) {
3538
{
3639
Config: apiKeyProjectAssignmentConfig(orgID, roleName, projectName),
3740
Check: apiKeyProjectAssignmentAttributeChecks(),
41+
ConfigStateChecks: []statecheck.StateCheck{
42+
statecheck.ExpectKnownValue(
43+
resourceName,
44+
tfjsonpath.New("roles"),
45+
knownvalue.SetExact([]knownvalue.Check{
46+
knownvalue.StringExact(roleName),
47+
}),
48+
),
49+
},
3850
},
3951
{
4052
Config: apiKeyProjectAssignmentConfig(orgID, roleNameUpdated, projectName),
4153
Check: apiKeyProjectAssignmentAttributeChecks(),
54+
ConfigStateChecks: []statecheck.StateCheck{
55+
statecheck.ExpectKnownValue(
56+
resourceName,
57+
tfjsonpath.New("roles"),
58+
knownvalue.SetExact([]knownvalue.Check{
59+
knownvalue.StringExact(roleNameUpdated),
60+
}),
61+
),
62+
},
4263
},
4364
{
4465
Config: apiKeyProjectAssignmentConfig(orgID, roleNameUpdated, projectName),
@@ -66,7 +87,7 @@ func apiKeyProjectAssignmentAttributeChecks() resource.TestCheckFunc {
6687
attrsMap := map[string]string{
6788
"roles.#": "1",
6889
}
69-
attrsSet := []string{"project_id", "api_key_id", "roles.0"}
90+
attrsSet := []string{"project_id", "api_key_id"}
7091
checks := []resource.TestCheckFunc{
7192
checkExists(resourceName),
7293
}

0 commit comments

Comments
 (0)