From 7188f323f719cbfb83c0c1e116fb30e5b9fc4064 Mon Sep 17 00:00:00 2001 From: Manuel Pedrozo Date: Mon, 29 Sep 2025 11:23:42 +0200 Subject: [PATCH] Fix database-user sample request helpers --- CONTRIBUTING.md | 6 +-- TESTING.md | 2 +- .../databaseuser.create-sample-cfn-request.sh | 4 +- ...tabaseuser.iamrole.sample-cfn-request.json | 43 ++++++++----------- .../test/databaseuser.sample-cfn-request.json | 41 ++++++++---------- 5 files changed, 44 insertions(+), 52 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index e29114c74..0132dc3ea 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -10,16 +10,16 @@ After the above 2 steps are completed and we've agreed on a path forward: 2. Create a branch with a name that briefly describes your submission 3. Add comments around your new code that explain what's happening 4. Commit and push your changes to your branch then submit a pull request against the current release branch, not master. The naming scheme of the branch is `release-staging-v#.#.#`. **Note**: There will only be one release branch at a time. -5. A repo maintainer will review the your pull request, and may either request additional changes or merge the pull request. +5. A repo maintainer will review your pull request, and may either request additional changes or merge the pull request. ## Requirements -- Resources configurations, specifcally `.rpdk-config` and `Makefile` build commands, are compatible with cloudformation-cli (`cfn`) versions 0.2.34 and above. +- Resources configurations, specifically `.rpdk-config` and `Makefile` build commands, are compatible with cloudformation-cli (`cfn`) versions 0.2.34 and above. ## Code and Test Best Practices -- Each resource is implemented in a seperate directory within `./cfn-resources`. Under each resource directory operations will be implemented in `./cmd/resource/resource.go`, having a separate file `./cmd/resource/mappings.go` for defining conversion logic with respective SDK and CFN models. +- Each resource is implemented in a separate directory within `./cfn-resources`. Under each resource directory operations will be implemented in `./cmd/resource/resource.go`, having a separate file `./cmd/resource/mappings.go` for defining conversion logic with respective SDK and CFN models. - Associated unit testing files must be defined for conversion logic, and can also exist for other business logic such as handling state transitions. Unit tests are defined under `resource_test` package to minimize coupling. - [Testify Mock](https://pkg.go.dev/github.com/stretchr/testify/mock) and [Mockery](https://github.com/vektra/mockery) are used for test doubles in unit tests. Mocked interfaces are generated in folder `cfn-resources/testutil/mocksvc`. - We have a `/test/README.md` for every resource in `cfn-resources`. You will also find [TESTING.md](./TESTING.md) which provides testing practices common to all resources. diff --git a/TESTING.md b/TESTING.md index 3bc4fcd3f..881c17b8f 100644 --- a/TESTING.md +++ b/TESTING.md @@ -7,7 +7,7 @@ This file contains the steps to follow to test any changes to the CFN resources. ### Prerequisites - Install [AtlasCLI](https://www.mongodb.com/docs/atlas/cli/stable/install-atlas-cli/) and [configure the default profile](https://www.mongodb.com/docs/atlas/cli/stable/connect-atlas-cli/#select-a-connection-method) on your machine as the scripts use Atlas CLI - Ensure [AWS CLI](https://aws.amazon.com/cli/), [CFN CLI](https://docs.aws.amazon.com/cloudformation-cli/latest/userguide/what-is-cloudformation-cli.html), [SAM CLI](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/install-sam-cli.html) are installed and configured correctly for your AWS account - - Configure an Atlas profile secret in AWS account with your API keys. Refer [README](../../../README.md) for more information on how to do this + - Configure an Atlas profile secret in AWS account with your API keys. Refer to [README](README.md) for more information on how to do this - Have Docker running on your machine - Refer to the prerequisites for your resource in the `cfn-resources/[resource-folder]/test` diff --git a/cfn-resources/database-user/test/databaseuser.create-sample-cfn-request.sh b/cfn-resources/database-user/test/databaseuser.create-sample-cfn-request.sh index bcbe0f42d..c9914c0f9 100755 --- a/cfn-resources/database-user/test/databaseuser.create-sample-cfn-request.sh +++ b/cfn-resources/database-user/test/databaseuser.create-sample-cfn-request.sh @@ -20,8 +20,8 @@ projectId="${1}" username="${2}" password="${3}" -jq --arg ProjectId "$projectId" \ +jq --arg projectId "$projectId" \ --arg username "$username" \ --arg password "$password" \ - '.desiredResourceState.properties.Username?|=$username | .desiredResourceState.properties.Password?|=$password | .desiredResourceState.properties.ProjectId?|=$projectId' \ + '.desiredResourceState.Username?|=$username | .desiredResourceState.Password?|=$password | .desiredResourceState.ProjectId?|=$projectId' \ "$(dirname "$0")/databaseuser.sample-cfn-request.json" diff --git a/cfn-resources/database-user/test/databaseuser.iamrole.sample-cfn-request.json b/cfn-resources/database-user/test/databaseuser.iamrole.sample-cfn-request.json index 5b333a9ec..f5869bc2c 100644 --- a/cfn-resources/database-user/test/databaseuser.iamrole.sample-cfn-request.json +++ b/cfn-resources/database-user/test/databaseuser.iamrole.sample-cfn-request.json @@ -1,26 +1,21 @@ { - "desiredResourceState" : { - "resourceType" : "MongoDB::Atlas::DatabaseUser", - "properties" : { - "Username" : "Name", - "ProjectId" : "ProjectId", - "Profile" :"", - "DatabaseName": "$external", - "AWSIAMType": "ROLE", - "Roles": [ - { "RoleName": "readWrite", - "DatabaseName": "testdb" - } - ], - "Scopes": [ - { "Type": "CLUSTER", - "Name": "testdb" - } - ] - - - } - }, - "providerLogGroupName" : "mongodb-atlas-databaseuser-logs", - "previousResourceState": { } + "desiredResourceState" : { + "Username": "Name", + "ProjectId": "ProjectId", + "Profile":"", + "DatabaseName": "$external", + "AWSIAMType": "ROLE", + "Roles": [ + { "RoleName": "readWrite", + "DatabaseName": "testdb" + } + ], + "Scopes": [ + { "Type": "CLUSTER", + "Name": "testdb" + } + ] + }, + "providerLogGroupName" : "mongodb-atlas-databaseuser-logs", + "previousResourceState": { } } diff --git a/cfn-resources/database-user/test/databaseuser.sample-cfn-request.json b/cfn-resources/database-user/test/databaseuser.sample-cfn-request.json index b0439181f..1f0130726 100644 --- a/cfn-resources/database-user/test/databaseuser.sample-cfn-request.json +++ b/cfn-resources/database-user/test/databaseuser.sample-cfn-request.json @@ -1,24 +1,21 @@ { - "desiredResourceState" : { - "resourceType" : "MongoDB::Atlas::DatabaseUser", - "properties" : { - "Username" : "Name", - "Password" : "Name", - "ProjectId" : "ProjectId", - "Profile" : "", - "DatabaseName": "admin", - "Roles": [ - { "RoleName": "readWrite", - "DatabaseName": "testdb" - } - ], - "Scopes": [ - { "Type": "CLUSTER", - "Name": "testdb" - } - ] - } - }, - "providerLogGroupName" : "mongodb-atlas-databaseuser-logs", - "previousResourceState": { } + "desiredResourceState" : { + "Username": "Name", + "Password": "Name", + "ProjectId": "ProjectId", + "Profile": "", + "DatabaseName": "admin", + "Roles": [ + { "RoleName": "readWrite", + "DatabaseName": "testdb" + } + ], + "Scopes": [ + { "Type": "CLUSTER", + "Name": "testdb" + } + ] + }, + "providerLogGroupName" : "mongodb-atlas-databaseuser-logs", + "previousResourceState": { } }