-
-
Notifications
You must be signed in to change notification settings - Fork 550
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CI: Ensure immutability of test cases #1712
Merged
+2,653
−0
Merged
Changes from 12 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
33f802c
CI: Check immutability of test data
SaschaMann b53c12d
Iterate old cases instead
SaschaMann f3a382e
Add to ci.yml workflow
SaschaMann e28ae59
Fix path to python script in workflow
SaschaMann b053497
Set chmod=+x for python script
SaschaMann ff3126f
Apparently latest does not mean latest
SaschaMann c1cf71e
Fix path
SaschaMann 18dbfa2
Test mutated test in PR
SaschaMann b4bfd32
Revert "Test mutated test in PR"
SaschaMann 137a9f0
Fix build for workflow_dispatch triggers
SaschaMann d8c7384
Break out of loop early on failure
SaschaMann b578e4c
Fix typo
SaschaMann b010ec0
Handle removal of tests better
SaschaMann af3969e
Add scenarios check
SaschaMann 6b6c042
Update bin/check-immutability.py
SaschaMann dd2e348
Make variable names longer & use sys.exit instead of exit
SaschaMann ce4ea11
Add test data for future edits to the script
SaschaMann File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#!/usr/bin/env python | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Python 3.8 is the default Python in the GHA env. |
||
|
||
import json | ||
import subprocess | ||
SaschaMann marked this conversation as resolved.
Show resolved
Hide resolved
|
||
import sys | ||
|
||
oldf = sys.argv[1] | ||
newf = sys.argv[2] | ||
|
||
immutable_keys = ('property', 'input', 'expected') | ||
|
||
# Use jq to flatten the test data, and parse it | ||
old = json.loads(subprocess.run([f"jq -r '[.. | objects | select(.uuid != null)]' {oldf}"], stdout=subprocess.PIPE, shell=True).stdout.decode('utf-8')) | ||
new = json.loads(subprocess.run([f"jq -r '[.. | objects | select(.uuid != null)]' {newf}"], stdout=subprocess.PIPE, shell=True).stdout.decode('utf-8')) | ||
SaschaMann marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
# Convert new to dict uuid => case | ||
new = {c['uuid']: c for c in new} | ||
SaschaMann marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
fails = set() | ||
|
||
# Iterate through old cases as only those could potentially be mutated | ||
for case in old: | ||
for k in immutable_keys: | ||
if case[k] != new[case['uuid']][k]: | ||
fails.add(case['uuid']) | ||
break | ||
SaschaMann marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
if len(fails) == 0: | ||
exit(0) | ||
SaschaMann marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
print('The following tests contain illegal mutations:') | ||
for f in fails: | ||
print(f" - {f} ({new[f]['description']})") | ||
exit(1) | ||
SaschaMann marked this conversation as resolved.
Show resolved
Hide resolved
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is only gonna work reliably on the main branch fwiw