Skip to content

Commit 2207423

Browse files
Add contract testing workflow, use http util functions
1 parent d9f1ced commit 2207423

3 files changed

Lines changed: 55 additions & 7 deletions

File tree

.github/workflows/contract-testing.yaml

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ jobs:
1515
alert-configuration: ${{ steps.filter.outputs.alert-configuration }}
1616
api-key: ${{ steps.filter.outputs.api-key }}
1717
auditing: ${{ steps.filter.outputs.auditing }}
18+
backup-compliance-policy: ${{ steps.filter.outputs.backup-compliance-policy }}
1819
cloud-backup-restore-jobs: ${{ steps.filter.outputs.cloud-backup-restore-jobs }}
1920
cluster-outage-simulation: ${{ steps.filter.outputs.cluster-outage-simulation }}
2021
federated-database-instance: ${{ steps.filter.outputs.federated-database-instance }}
@@ -46,6 +47,8 @@ jobs:
4647
- 'cfn-resources/api-key/**'
4748
auditing:
4849
- 'cfn-resources/auditing/**'
50+
backup-compliance-policy:
51+
- 'cfn-resources/backup-compliance-policy/**'
4952
cloud-backup-restore-jobs:
5053
- 'cfn-resources/cloud-backup-restore-jobs/**'
5154
cluster-outage-simulation:
@@ -237,7 +240,48 @@ jobs:
237240
cat inputs/inputs_1_update.json
238241
cat inputs/inputs_2_create.json
239242
cat inputs/inputs_2_update.json
240-
243+
244+
make run-contract-testing
245+
make delete-test-resources
246+
backup-compliance-policy:
247+
needs: change-detection
248+
if: ${{ needs.change-detection.outputs.backup-compliance-policy == 'true' }}
249+
runs-on: ubuntu-latest
250+
steps:
251+
- uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8
252+
- uses: actions/setup-go@7a3fe6cf4cb3a834922a1244abfce67bcef6a0c5
253+
with:
254+
go-version-file: 'cfn-resources/go.mod'
255+
- name: setup Atlas CLI
256+
uses: mongodb/atlas-github-action@e3c9e0204659bafbb3b65e1eb1ee745cca0e9f3b
257+
- uses: aws-actions/setup-sam@c2a20b1822cc4a6bc594ff7f1dbb658758e383c3
258+
with:
259+
use-installer: true
260+
- uses: aws-actions/configure-aws-credentials@61815dcd50bd041e203e49132bacad1fd04d2708
261+
with:
262+
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID_TEST_ENV }}
263+
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY_TEST_ENV }}
264+
aws-region: eu-west-1
265+
- uses: actions/setup-python@83679a892e2d95755f2dac6acb0bfd1e9ac5d548
266+
with:
267+
python-version: '3.9'
268+
cache: 'pip' # caching pip dependencies
269+
- run: pip install cloudformation-cli cloudformation-cli-go-plugin
270+
- name: Run the Contract test
271+
shell: bash
272+
env:
273+
MONGODB_ATLAS_PUBLIC_API_KEY: ${{ secrets.CLOUD_DEV_PUBLIC_KEY }}
274+
MONGODB_ATLAS_PRIVATE_API_KEY: ${{ secrets.CLOUD_DEV_PRIVATE_KEY }}
275+
MONGODB_ATLAS_ORG_ID: ${{ secrets.CLOUD_DEV_ORG_ID }}
276+
MONGODB_ATLAS_OPS_MANAGER_URL: ${{ vars.MONGODB_ATLAS_BASE_URL }}
277+
MONGODB_ATLAS_PROFILE: cfn-cloud-dev-github-action
278+
run: |
279+
cd cfn-resources/backup-compliance-policy
280+
make create-test-resources
281+
282+
cat inputs/inputs_1_create.json
283+
cat inputs/inputs_1_update.json
284+
241285
make run-contract-testing
242286
make delete-test-resources
243287
cloud-backup-restore-jobs:

cfn-resources/backup-compliance-policy/Makefile

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,11 @@ clean:
2020

2121
create-test-resources:
2222
@echo "==> Creating test files for contract testing"
23-
./test/contract-testing/cfn-test-create-inputs.sh
23+
./test/contract-testing/cfn-test-create.sh
24+
25+
delete-test-resources:
26+
@echo "==> Delete test resources used for contract testing"
27+
./test/contract-testing/cfn-test-delete.sh
2428

2529
run-contract-testing:
2630
@echo "==> Run contract testing"

cfn-resources/backup-compliance-policy/cmd/resource/share.go renamed to cfn-resources/backup-compliance-policy/cmd/resource/handlers.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ func handlePendingAction(ctx context.Context, client *util.MongoDBClient, model
6060

6161
func checkPolicyNotFound(policy *admin.DataProtectionSettings20231001, apiResp *http.Response, err error, projectID string, operation constants.CfnFunctions) *handler.ProgressEvent {
6262
if err != nil {
63-
if apiResp != nil && apiResp.StatusCode == http.StatusNotFound {
63+
if util.StatusNotFound(apiResp) {
6464
pe := progress_events.GetFailedEventByCode(
6565
"Backup Compliance Policy not found for project: "+projectID,
6666
string(types.HandlerErrorCodeNotFound))
@@ -90,7 +90,7 @@ func HandleCreate(req *handler.Request, client *util.MongoDBClient, model *Model
9090

9191
existingPolicy, apiResp, err := client.AtlasSDK.CloudBackupsApi.GetCompliancePolicy(ctx, projectID).Execute()
9292
if err != nil {
93-
if apiResp == nil || apiResp.StatusCode != http.StatusNotFound {
93+
if !util.StatusNotFound(apiResp) {
9494
return handleError(apiResp, constants.CREATE, err)
9595
}
9696
} else if existingPolicy != nil && existingPolicy.GetState() == policyStateActive {
@@ -210,7 +210,7 @@ func HandleDelete(req *handler.Request, client *util.MongoDBClient, model *Model
210210
return handlePendingAction(ctx, client, model, projectID)
211211
}
212212

213-
if apiResp != nil && apiResp.StatusCode == http.StatusNotFound {
213+
if util.StatusNotFound(apiResp) {
214214
return handler.ProgressEvent{
215215
OperationStatus: handler.Success,
216216
Message: constants.Complete,
@@ -227,7 +227,7 @@ func HandleList(req *handler.Request, client *util.MongoDBClient, model *Model)
227227

228228
policy, apiResp, err := client.AtlasSDK.CloudBackupsApi.GetCompliancePolicy(ctx, projectID).Execute()
229229
if err != nil {
230-
if apiResp == nil || apiResp.StatusCode != http.StatusNotFound {
230+
if !util.StatusNotFound(apiResp) {
231231
return handleError(apiResp, constants.LIST, err)
232232
}
233233
return handler.ProgressEvent{
@@ -274,7 +274,7 @@ func validateProgress(client *util.MongoDBClient, model *Model, isDelete bool) h
274274
projectID := *model.ProjectId
275275

276276
policy, resp, err := client.AtlasSDK.CloudBackupsApi.GetCompliancePolicy(ctx, projectID).Execute()
277-
notFound := resp != nil && resp.StatusCode == http.StatusNotFound
277+
notFound := util.StatusNotFound(resp)
278278
policyDeleted := notFound || (policy != nil && policy.GetProjectId() == "")
279279

280280
if err != nil && !notFound {

0 commit comments

Comments
 (0)