Skip to content

Commit

Permalink
Test or TestAccResourceMongoDBAtlasDatabaseUser_withAWSIAMType with (#…
Browse files Browse the repository at this point in the history
…432)

* Test or TestAccResourceMongoDBAtlasDatabaseUser_withAWSIAMType with
import

1. Why is this change necessary?
Test for a import is a nice to have

2. How does it address the issue?
Test the function with the import for a matching scenario

3. What side effects does this change have?
None known

* username set in env var

1. Why is this change necessary?
Modular testing

2. How does it address the issue?
Make the username variable in that particular test dependentant on a env
var

3. What side effects does this change have?
None
  • Loading branch information
pitakill authored Apr 15, 2021
1 parent 733570c commit 135e66f
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions mongodbatlas/resource_mongodbatlas_database_user_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,47 @@ func TestAccResourceMongoDBAtlasDatabaseUser_withAWSIAMType(t *testing.T) {
})
}

func TestAccResourceMongoDBAtlasDatabaseUser_withAWSIAMType_import(t *testing.T) {
var (
dbUser matlas.DatabaseUser
resourceName = "mongodbatlas_database_user.test"
username = os.Getenv("TEST_DB_USER_IAM_ARN")
orgID = os.Getenv("MONGODB_ATLAS_ORG_ID")
projectName = acctest.RandomWithPrefix("test-acc")
)

if username == "" {
username = "arn:aws:iam::358363220050:user/mongodb-aws-iam-auth-test-user"
}

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckMongoDBAtlasDatabaseUserDestroy,
Steps: []resource.TestStep{
{
Config: testAccMongoDBAtlasDatabaseUserWithAWSIAMTypeConfig(projectName, orgID, "atlasAdmin", username, "First Key", "First value"),
Check: resource.ComposeTestCheckFunc(
testAccCheckMongoDBAtlasDatabaseUserExists(resourceName, &dbUser),
testAccCheckMongoDBAtlasDatabaseUserAttributes(&dbUser, username),
resource.TestCheckResourceAttrSet(resourceName, "project_id"),
resource.TestCheckResourceAttr(resourceName, "username", username),
resource.TestCheckResourceAttr(resourceName, "aws_iam_type", "USER"),
resource.TestCheckResourceAttr(resourceName, "auth_database_name", "$external"),
resource.TestCheckResourceAttr(resourceName, "labels.#", "1"),
),
},
{
ResourceName: resourceName,
ImportStateIdFunc: testAccCheckMongoDBAtlasDatabaseUserImportStateIDFunc(resourceName),
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"password"},
},
},
})
}

func TestAccResourceMongoDBAtlasDatabaseUser_WithLabels(t *testing.T) {
var (
dbUser matlas.DatabaseUser
Expand Down

0 comments on commit 135e66f

Please sign in to comment.