Skip to content

Commit

Permalink
Update snapshot tests to integrate new custom-json-diff functionality.
Browse files Browse the repository at this point in the history
Signed-off-by: Caroline Russell <[email protected]>
  • Loading branch information
cerrussell committed Jun 7, 2024
1 parent 37b8e54 commit dbfe581
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 22 deletions.
15 changes: 7 additions & 8 deletions .github/workflows/snapshot-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on:
workflow_dispatch:
pull_request:
branches:
- main
- master


concurrency:
Expand Down Expand Up @@ -38,10 +38,8 @@ jobs:
python -m pip install --upgrade pip
python -m pip install pytest
git clone https://github.com/appthreat/cdxgen-samples.git /home/runner/work/samples
git clone https://github.com/appthreat/custom-json-diff.git /home/runner/work/custom-json-diff
cd /home/runner/work/custom-json-diff
python -m pip install .
corepack pnpm install -g @appthreat/atom
python -m pip install custom-json-diff
npm install -g @appthreat/atom
curl -s "https://get.sdkman.io" | bash
source "/home/runner/.sdkman/bin/sdkman-init.sh"
Expand Down Expand Up @@ -87,9 +85,10 @@ jobs:
if: ${{ env.status == 'FAILED' }}
uses: actions/upload-artifact@v4
with:
name: diff
path: /home/runner/work/cdxgen-samples/diffs.json
path: |
/home/runner/work/cdxgen-samples/diffs.json
/home/runner/work/cdxgen-samples/*.html
- name: Exit with error
if: ${{ env.status == 'FAILED' }}
run: exit 1
run: exit 1
39 changes: 25 additions & 14 deletions test/diff/diff_tests.py
Original file line number Diff line number Diff line change
@@ -1,34 +1,45 @@
import csv
import json
import os
from pathlib import Path

from custom_json_diff.custom_diff import compare_dicts, get_diffs
from custom_json_diff.custom_diff import compare_dicts, perform_bom_diff, report_results
from custom_json_diff.custom_diff_classes import Options


with open('/home/runner/work/cdxgen/cdxgen/test/diff/repos.csv', 'r', encoding='utf-8') as f:
reader = csv.DictReader(f)
repo_data = list(reader)

Failed = False
failed_diffs = {}

for i in repo_data:
bom_file = f'{i["project"]}-bom.json'
bom_1 = Path("/home/runner/work/samples", bom_file)
bom_2 = Path("/home/runner/work/cdxgen-samples", bom_file)
bom_1 = f"/home/runner/work/samples/{bom_file}"
bom_2 = f"/home/runner/work/cdxgen-samples/{bom_file}"
exclude = []
include = []
options = Options(
allow_new_versions=True,
allow_new_data=True,
bom_diff=True,
include=include,
exclude=exclude,
file_1=bom_1,
file_2=bom_2,
output=f'/home/runner/work/cdxgen-samples/{i["project"]}-diff.json'
)
if not os.path.exists(bom_1):
print(f'{bom_file} does not exist in cdxgen-samples repository.')
failed_diffs[i["project"]] = f'{bom_file} does not exist in cdxgen-samples repository.'
continue
result, j1, j2 = compare_dicts(bom_1, bom_2, preset="cdxgen")
if result == 0:
print(f'{i["project"]} BOM passed.')
else:
print(f'{i["project"]} BOM failed.')
Failed = True
diffs = get_diffs(bom_1, bom_2, j1, j2)
failed_diffs[i["project"]] = diffs
result, j1, j2 = compare_dicts(options)

if result != 0:
print(f"{i['project']} failed.")
result_summary = perform_bom_diff(j1, j2)
failed_diffs[i["project"]] = result_summary
report_results(result, result_summary, options, j1, j2)

if failed_diffs:
with open('/home/runner/work/cdxgen-samples/diffs.json', 'w') as f:
json.dump(failed_diffs, f, indent=2)
json.dump(failed_diffs, f)

0 comments on commit dbfe581

Please sign in to comment.