Skip to content

Commit

Permalink
CLOUDP-278958: trasformation test (#306)
Browse files Browse the repository at this point in the history
  • Loading branch information
wtrocki authored Dec 12, 2024
1 parent 7a1fb77 commit c4d5cb9
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 4 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/release-postman.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ jobs:
BASE_URL: ${{ inputs.atlas_prod_base_url }}
working-directory: ./tools/postman
run: |
make transform_collection
make transform_collection
make transform_collection_test
- name: Upload Collection to Postman
env:
Expand Down
4 changes: 4 additions & 0 deletions tools/postman/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ convert_to_collection:
transform_collection:
./scripts/transform-for-api.sh

.PHONY: transform_collection_test
transform_collection_test:
./scripts/transform-for-api-test.sh

.PHONY: upload_collection
upload_collection:
./scripts/upload-collection.sh
Expand Down
7 changes: 4 additions & 3 deletions tools/postman/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,10 @@ The OpenAPI path for Postman generation and configured feature flags can also be

Once env vars are configured, the setup scripts can be run locally using the Make following commands:
- `make fetch_openapi`
- `make convert_to_collection`
- `make transform_collection`
- `make upload_collection`
- `make convert_to_collection` - covert OpenAPI to Postman collection
- `make transform_collection` - transform Postman collection to fix common issues
- `make transform_collection_test` - test collection.
- `make upload_collection` - uploads collection to the Postman

## Automatic updates

Expand Down
43 changes: 43 additions & 0 deletions tools/postman/scripts/transform-for-api-test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/usr/bin/env bash
set -euo pipefail

#########################################################
# Test for transformation
# To be run after transformation is done
#########################################################

COLLECTION_FILE_NAME=${COLLECTION_FILE_NAME:-"collection.json"}
TMP_FOLDER=${TMP_FOLDER:-"../tmp"}
COLLECTION_TRANSFORMED_FILE_NAME=${COLLECTION_TRANSFORMED_FILE_NAME:-"collection-transformed.json"}

pushd "${TMP_FOLDER}"

# Ensure the necessary files exist
if [[ ! -f "$COLLECTION_FILE_NAME" ]]; then
echo "Error: Collection file not found at $COLLECTION_FILE_NAME"
exit 1
fi

# Test: Disable query params by default
echo "Disabling query params by default test"
if jq -e '.. | select(.request? != null).request.url.query[] | select(.disabled == true)' "$COLLECTION_TRANSFORMED_FILE_NAME" > /dev/null; then
echo "Test Passed: Query params disabled successfully."
else
echo "Test Failed: Query params disabling failed."
fi

# Test: Remove _postman_id
if ! jq -e '.collection.info._postman_id' "$COLLECTION_TRANSFORMED_FILE_NAME" > /dev/null; then
echo "Test Passed: _postman_id removed successfully."
else
echo "Test Failed: _postman_id removal failed."
fi

# Test : Add baseUrl property
echo "Adding baseUrl property test"
if jq -e '.collection.variable[0] | (.key == "baseUrl" and has("value"))' "$COLLECTION_TRANSFORMED_FILE_NAME" > /dev/null; then
echo "Test Passed: The first item in the variable array has key set to \"baseUrl\" and has a value property."
else
echo "Test Failed: The first item in the variable array does not have the expected key or value properties."
fi

0 comments on commit c4d5cb9

Please sign in to comment.