-
-
Notifications
You must be signed in to change notification settings - Fork 157
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update snapshot tests to integrate new custom-json-diff functionality.
Signed-off-by: Caroline Russell <[email protected]>
- Loading branch information
1 parent
37b8e54
commit dbfe581
Showing
2 changed files
with
32 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |