Skip to content

Commit c822df2

Browse files
committed
CLOUDP-278958: trasformation test
1 parent ac85871 commit c822df2

File tree

2 files changed

+91
-0
lines changed

2 files changed

+91
-0
lines changed

tools/postman/Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ convert_to_collection:
1717
transform_collection:
1818
./scripts/transform-for-api.sh
1919

20+
.PHONY: transform_collection_test
21+
transform_collection_test:
22+
./scripts/transform-for-api-test.sh
23+
2024
.PHONY: upload_collection
2125
upload_collection:
2226
./scripts/upload-collection.sh
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
#########################################################
5+
# Test for transformation
6+
# To be run after transformation is done
7+
#########################################################
8+
9+
COLLECTION_FILE_NAME=${COLLECTION_FILE_NAME:-"collection.json"}
10+
TMP_FOLDER=${TMP_FOLDER:-"../tmp"}
11+
COLLECTION_TRANSFORMED_FILE_NAME=${COLLECTION_TRANSFORMED_FILE_NAME:-"collection-transformed.json"}
12+
13+
pushd "${TMP_FOLDER}"
14+
15+
# Ensure the necessary files exist
16+
if [[ ! -f "$COLLECTION_FILE_NAME" ]]; then
17+
echo "Error: Collection file not found at $COLLECTION_FILE_NAME"
18+
exit 1
19+
fi
20+
21+
22+
# Test: Wrap Collection in "collection" tag
23+
echo "Wrapping Collection $COLLECTION_FILE_NAME in \"collection\" tag"
24+
jq '{"collection": .}' "$COLLECTION_FILE_NAME" > intermediateCollectionWrapped.json
25+
26+
if jq -e '.collection' intermediateCollectionWrapped.json > /dev/null; then
27+
echo "Test Passed: Collection wrapped successfully."
28+
else
29+
echo "Test Failed: Collection wrapping failed."
30+
fi
31+
32+
# Test: Disable query params by default
33+
echo "Disabling query params by default"
34+
# jq '(.. | select(.request? != null).request.url.query[].disabled) = true' \
35+
# intermediateCollectionWrapped.json > intermediateCollectionDisableQueryParam.json
36+
37+
if jq -e '.. | select(.request? != null).request.url.query[] | select(.disabled == true)' intermediateCollectionDisableQueryParam.json > /dev/null; then
38+
echo "Test Passed: Query params disabled successfully."
39+
else
40+
echo "Test Failed: Query params disabling failed."
41+
fi
42+
43+
# Test: Remove _postman_id
44+
# echo "Removing _postman_id"
45+
# jq 'del(.collection.info._postman_id)' \
46+
# intermediateCollectionDisableQueryParam.json > intermediateCollectionNoPostmanID.json
47+
48+
if ! jq -e '.collection.info._postman_id' intermediateCollectionNoPostmanID.json > /dev/null; then
49+
echo "Test Passed: _postman_id removed successfully."
50+
else
51+
echo "Test Failed: _postman_id removal failed."
52+
fi
53+
54+
# Test: Remove circular references
55+
echo "Removing circular references"
56+
sed 's/\\"value\\": \\"<Circular reference to #[^>"]* detected>\\"//g' intermediateCollectionNoPostmanID.json > intermediateCollectionNoCircular.json
57+
58+
if ! grep -q '<Circular reference to #' intermediateCollectionNoCircular.json; then
59+
echo "Test Passed: Circular references removed successfully."
60+
else
61+
echo "Test Failed: Circular references removal failed."
62+
fi
63+
64+
# Test: Remove all variables
65+
echo "Removing all variables. We use environment for variables instead"
66+
jq '.collection.variable = []' \
67+
intermediateCollectionWithDescription.json > intermediateCollectionWithNoVarjson.json
68+
69+
if jq -e '.collection.variable | length == 0' intermediateCollectionWithNoVarjson.json > /dev/null; then
70+
echo "Test Passed: Variables removed successfully."
71+
else
72+
echo "Test Failed: Variables removal failed."
73+
fi
74+
75+
# Test : Add baseUrl property
76+
echo "Adding baseUrl property $BASE_URL"
77+
jq --arg base_url "$BASE_URL" \
78+
'.collection.variable[0].value = $base_url' \
79+
intermediateCollectionWithNoVarjson.json > intermediateCollectionWithBaseURL.json
80+
81+
if jq -e --arg base_url "$BASE_URL" '.collection.variable[0].value == $base_url' intermediateCollectionWithBaseURL.json > /dev/null; then
82+
echo "Test Passed: baseUrl property added successfully."
83+
else
84+
echo "Test Failed: baseUrl property addition failed."
85+
fi
86+
87+
# End of test script

0 commit comments

Comments
 (0)