Skip to content

Commit cde01ee

Browse files
authored
Update snapshot script results file naming so that templates with sam… (#4575)
* Update snapshot script results file naming so that templates with same name do not conflict
1 parent 814451e commit cde01ee

38 files changed

Lines changed: 89 additions & 68 deletions

scripts/update_snapshot_results.sh

Lines changed: 42 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ done
1212
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
1313
PROJECT_DIR="$(cd "$SCRIPT_DIR/.." && pwd)"
1414

15+
# Run from the project root so all relative paths below resolve consistently
16+
# regardless of where the script was invoked from.
17+
cd "$PROJECT_DIR"
18+
1519
TEMPLATES_DIR="test/fixtures/templates"
1620
RESULTS_DIR="test/fixtures/results"
1721

@@ -55,47 +59,48 @@ main()
5559
# ============================================================================
5660

5761
# integration/
58-
run_lint "$TEMPLATES_DIR/integration/dynamic-references.yaml" "$RESULTS_DIR/integration/dynamic-references.json"
59-
run_lint "$TEMPLATES_DIR/integration/resources-cloudformation-init.yaml" "$RESULTS_DIR/integration/resources-cloudformation-init.json"
60-
run_lint "$TEMPLATES_DIR/integration/ref-no-value.yaml" "$RESULTS_DIR/integration/ref-no-value.json"
61-
run_lint "$TEMPLATES_DIR/integration/availability-zones.yaml" "$RESULTS_DIR/integration/availability-zones.json"
62-
run_lint "$TEMPLATES_DIR/integration/getatt-types.yaml" "$RESULTS_DIR/integration/getatt-types.json"
63-
run_lint "$TEMPLATES_DIR/integration/ref-types.yaml" "$RESULTS_DIR/integration/ref-types.json"
64-
run_lint "$TEMPLATES_DIR/integration/formats.yaml" "$RESULTS_DIR/integration/formats.json"
65-
run_lint "$TEMPLATES_DIR/integration/aws-ec2-networkinterface.yaml" "$RESULTS_DIR/integration/aws-ec2-networkinterface.json"
66-
run_lint "$TEMPLATES_DIR/integration/aws-ec2-instance.yaml" "$RESULTS_DIR/integration/aws-ec2-instance.json"
67-
run_lint "$TEMPLATES_DIR/integration/aws-ec2-launchtemplate.yaml" "$RESULTS_DIR/integration/aws-ec2-launchtemplate.json"
68-
run_lint "$TEMPLATES_DIR/integration/aws-ec2-subnet.yaml" "$RESULTS_DIR/integration/aws-ec2-subnet.json"
69-
run_lint "$TEMPLATES_DIR/integration/aws-dynamodb-table.yaml" "$RESULTS_DIR/integration/aws-dynamodb-table.json"
70-
run_lint "$TEMPLATES_DIR/integration/custom-resources.yaml" "$RESULTS_DIR/integration/custom-resources.json"
71-
run_lint "$TEMPLATES_DIR/integration/cfn-gather.yaml" "$RESULTS_DIR/integration/cfn-gather.json"
72-
run_lint "$TEMPLATES_DIR/integration/aws-lambda-function.yaml" "$RESULTS_DIR/integration/aws-lambda-function.json"
73-
run_lint "$TEMPLATES_DIR/integration/module-sub-resources.yaml" "$RESULTS_DIR/integration/module-sub-resources.json"
62+
run_lint "$TEMPLATES_DIR/integration/dynamic-references.yaml" "$RESULTS_DIR/integration/dynamic-references_yaml.json"
63+
run_lint "$TEMPLATES_DIR/integration/resources-cloudformation-init.yaml" "$RESULTS_DIR/integration/resources-cloudformation-init_yaml.json"
64+
run_lint "$TEMPLATES_DIR/integration/ref-no-value.yaml" "$RESULTS_DIR/integration/ref-no-value_yaml.json"
65+
run_lint "$TEMPLATES_DIR/integration/availability-zones.yaml" "$RESULTS_DIR/integration/availability-zones_yaml.json"
66+
run_lint "$TEMPLATES_DIR/integration/getatt-types.yaml" "$RESULTS_DIR/integration/getatt-types_yaml.json"
67+
run_lint "$TEMPLATES_DIR/integration/ref-types.yaml" "$RESULTS_DIR/integration/ref-types_yaml.json"
68+
run_lint "$TEMPLATES_DIR/integration/formats.yaml" "$RESULTS_DIR/integration/formats_yaml.json"
69+
run_lint "$TEMPLATES_DIR/integration/aws-ec2-networkinterface.yaml" "$RESULTS_DIR/integration/aws-ec2-networkinterface_yaml.json"
70+
run_lint "$TEMPLATES_DIR/integration/aws-ec2-instance.yaml" "$RESULTS_DIR/integration/aws-ec2-instance_yaml.json"
71+
run_lint "$TEMPLATES_DIR/integration/aws-ec2-launchtemplate.yaml" "$RESULTS_DIR/integration/aws-ec2-launchtemplate_yaml.json"
72+
run_lint "$TEMPLATES_DIR/integration/aws-ec2-subnet.yaml" "$RESULTS_DIR/integration/aws-ec2-subnet_yaml.json"
73+
run_lint "$TEMPLATES_DIR/integration/aws-dynamodb-table.yaml" "$RESULTS_DIR/integration/aws-dynamodb-table_yaml.json"
74+
run_lint "$TEMPLATES_DIR/integration/custom-resources.yaml" "$RESULTS_DIR/integration/custom-resources_yaml.json"
75+
run_lint "$TEMPLATES_DIR/integration/cfn-gather.yaml" "$RESULTS_DIR/integration/cfn-gather_yaml.json"
76+
run_lint "$TEMPLATES_DIR/integration/aws-lambda-function.yaml" "$RESULTS_DIR/integration/aws-lambda-function_yaml.json"
77+
run_lint "$TEMPLATES_DIR/integration/module-sub-resources.yaml" "$RESULTS_DIR/integration/module-sub-resources_yaml.json"
78+
run_lint "$TEMPLATES_DIR/integration/get-stack-output.yaml" "$RESULTS_DIR/integration/get-stack-output_yaml.json"
7479

7580
# integration/ special name mapping (template has typo: metdata)
76-
run_lint "$TEMPLATES_DIR/integration/metdata.yaml" "$RESULTS_DIR/integration/metadata.json"
81+
run_lint "$TEMPLATES_DIR/integration/metdata.yaml" "$RESULTS_DIR/integration/metadata_yaml.json"
7782

7883
# public/ (watchmaker needs strict E3012)
79-
run_lint "$TEMPLATES_DIR/public/lambda-poller.yaml" "$RESULTS_DIR/public/lambda-poller.json"
80-
run_lint "$TEMPLATES_DIR/public/watchmaker.json" "$RESULTS_DIR/public/watchmaker.json" -x E3012:strict=true
84+
run_lint "$TEMPLATES_DIR/public/lambda-poller.yaml" "$RESULTS_DIR/public/lambda-poller_yaml.json"
85+
run_lint "$TEMPLATES_DIR/public/watchmaker.json" "$RESULTS_DIR/public/watchmaker_json.json" -x E3012:strict=true
8186

8287
# quickstart/non_strict/
83-
run_lint "$TEMPLATES_DIR/quickstart/cis_benchmark.yaml" "$RESULTS_DIR/quickstart/non_strict/cis_benchmark.json"
84-
run_lint "$TEMPLATES_DIR/quickstart/nist_application.yaml" "$RESULTS_DIR/quickstart/non_strict/nist_application.json"
85-
run_lint "$TEMPLATES_DIR/quickstart/nist_high_main.yaml" "$RESULTS_DIR/quickstart/non_strict/nist_high_main.json"
86-
run_lint "$TEMPLATES_DIR/quickstart/openshift.yaml" "$RESULTS_DIR/quickstart/non_strict/openshift.json"
88+
run_lint "$TEMPLATES_DIR/quickstart/cis_benchmark.yaml" "$RESULTS_DIR/quickstart/non_strict/cis_benchmark_yaml.json"
89+
run_lint "$TEMPLATES_DIR/quickstart/nist_application.yaml" "$RESULTS_DIR/quickstart/non_strict/nist_application_yaml.json"
90+
run_lint "$TEMPLATES_DIR/quickstart/nist_high_main.yaml" "$RESULTS_DIR/quickstart/non_strict/nist_high_main_yaml.json"
91+
run_lint "$TEMPLATES_DIR/quickstart/openshift.yaml" "$RESULTS_DIR/quickstart/non_strict/openshift_yaml.json"
8792

8893
# quickstart/ (strict E3012)
89-
run_lint "$TEMPLATES_DIR/quickstart/cis_benchmark.yaml" "$RESULTS_DIR/quickstart/cis_benchmark.json" -x E3012:strict=true
90-
run_lint "$TEMPLATES_DIR/quickstart/nist_application.yaml" "$RESULTS_DIR/quickstart/nist_application.json" -x E3012:strict=true
91-
run_lint "$TEMPLATES_DIR/quickstart/nist_config_rules.yaml" "$RESULTS_DIR/quickstart/nist_config_rules.json" -x E3012:strict=true
92-
run_lint "$TEMPLATES_DIR/quickstart/nist_high_main.yaml" "$RESULTS_DIR/quickstart/nist_high_main.json" -x E3012:strict=true
93-
run_lint "$TEMPLATES_DIR/quickstart/nist_iam.yaml" "$RESULTS_DIR/quickstart/nist_iam.json" -x E3012:strict=true
94-
run_lint "$TEMPLATES_DIR/quickstart/nist_logging.yaml" "$RESULTS_DIR/quickstart/nist_logging.json" -x E3012:strict=true
95-
run_lint "$TEMPLATES_DIR/quickstart/nist_vpc_management.yaml" "$RESULTS_DIR/quickstart/nist_vpc_management.json" -x E3012:strict=true
96-
run_lint "$TEMPLATES_DIR/quickstart/nist_vpc_production.yaml" "$RESULTS_DIR/quickstart/nist_vpc_production.json" -x E3012:strict=true
97-
run_lint "$TEMPLATES_DIR/quickstart/openshift.yaml" "$RESULTS_DIR/quickstart/openshift.json" -x E3012:strict=true
98-
run_lint "$TEMPLATES_DIR/quickstart/openshift_master.yaml" "$RESULTS_DIR/quickstart/openshift_master.json" -x E3012:strict=true
94+
run_lint "$TEMPLATES_DIR/quickstart/cis_benchmark.yaml" "$RESULTS_DIR/quickstart/cis_benchmark_yaml.json" -x E3012:strict=true
95+
run_lint "$TEMPLATES_DIR/quickstart/nist_application.yaml" "$RESULTS_DIR/quickstart/nist_application_yaml.json" -x E3012:strict=true
96+
run_lint "$TEMPLATES_DIR/quickstart/nist_config_rules.yaml" "$RESULTS_DIR/quickstart/nist_config_rules_yaml.json" -x E3012:strict=true
97+
run_lint "$TEMPLATES_DIR/quickstart/nist_high_main.yaml" "$RESULTS_DIR/quickstart/nist_high_main_yaml.json" -x E3012:strict=true
98+
run_lint "$TEMPLATES_DIR/quickstart/nist_iam.yaml" "$RESULTS_DIR/quickstart/nist_iam_yaml.json" -x E3012:strict=true
99+
run_lint "$TEMPLATES_DIR/quickstart/nist_logging.yaml" "$RESULTS_DIR/quickstart/nist_logging_yaml.json" -x E3012:strict=true
100+
run_lint "$TEMPLATES_DIR/quickstart/nist_vpc_management.yaml" "$RESULTS_DIR/quickstart/nist_vpc_management_yaml.json" -x E3012:strict=true
101+
run_lint "$TEMPLATES_DIR/quickstart/nist_vpc_production.yaml" "$RESULTS_DIR/quickstart/nist_vpc_production_yaml.json" -x E3012:strict=true
102+
run_lint "$TEMPLATES_DIR/quickstart/openshift.yaml" "$RESULTS_DIR/quickstart/openshift_yaml.json" -x E3012:strict=true
103+
run_lint "$TEMPLATES_DIR/quickstart/openshift_master.yaml" "$RESULTS_DIR/quickstart/openshift_master_yaml.json" -x E3012:strict=true
99104

100105
# ============================================================================
101106
# Auto-discover remaining templates not handled above (requires --auto-discover)
@@ -115,9 +120,11 @@ while read -r template; do
115120
continue
116121
fi
117122

118-
# Compute result path: replace templates/ with results/, change extension to .json
123+
# Compute result path: replace templates/ with results/, fold the template
124+
# extension into the name as an underscore suffix so json/yaml/yml templates
125+
# with the same name don't clobber each other (e.g. foo.yaml -> foo_yaml.json).
119126
relative="${template#$TEMPLATES_DIR/}"
120-
result_file="$RESULTS_DIR/${relative%.*}.json"
127+
result_file="$RESULTS_DIR/${relative%.*}_${relative##*.}.json"
121128

122129
# Skip if another template already wrote this result file during this run
123130
if grep -qxF "$result_file" "$WRITTEN"; then

test/fixtures/results/integration/availability-zones.json renamed to test/fixtures/results/integration/availability-zones_yaml.json

File renamed without changes.

test/fixtures/results/integration/aws-dynamodb-table.json renamed to test/fixtures/results/integration/aws-dynamodb-table_yaml.json

File renamed without changes.

test/fixtures/results/integration/aws-ec2-instance.json renamed to test/fixtures/results/integration/aws-ec2-instance_yaml.json

File renamed without changes.

test/fixtures/results/integration/aws-ec2-launchtemplate.json renamed to test/fixtures/results/integration/aws-ec2-launchtemplate_yaml.json

File renamed without changes.

test/fixtures/results/integration/aws-ec2-networkinterface.json renamed to test/fixtures/results/integration/aws-ec2-networkinterface_yaml.json

File renamed without changes.

test/fixtures/results/integration/aws-ec2-subnet.json renamed to test/fixtures/results/integration/aws-ec2-subnet_yaml.json

File renamed without changes.

test/fixtures/results/integration/aws-lambda-function.json renamed to test/fixtures/results/integration/aws-lambda-function_yaml.json

File renamed without changes.
File renamed without changes.

test/fixtures/results/integration/custom-resources.json renamed to test/fixtures/results/integration/custom-resources_yaml.json

File renamed without changes.

0 commit comments

Comments
 (0)