Skip to content

Commit

Permalink
Add tests for requiring reasonable commit size policy
Browse files Browse the repository at this point in the history
  • Loading branch information
michieldewilde committed Mar 1, 2024
1 parent c9b801a commit 986853d
Showing 1 changed file with 207 additions and 0 deletions.
207 changes: 207 additions & 0 deletions plan/require-reasonable-commit-size_test.rego
Original file line number Diff line number Diff line change
@@ -0,0 +1,207 @@
package spacelift

# Test case for denying proposed run with too many changes.
test_deny_for_proposed_run_with_too_many_changes {

Check failure on line 4 in plan/require-reasonable-commit-size_test.rego

View workflow job for this annotation

GitHub Actions / Regal Check

Max rule length exceeded. To learn more, see: https://docs.styra.com/regal/rules/style/rule-length
inp := {
"spacelift": {"run": {"type": "PROPOSED"}},
"terraform": {"resource_changes": [
{"change": {"actions": ["delete"]}},
{"change": {"actions": ["delete"]}},
{"change": {"actions": ["delete"]}},
{"change": {"actions": ["delete"]}},
{"change": {"actions": ["delete"]}},
{"change": {"actions": ["delete"]}},
{"change": {"actions": ["delete"]}},
{"change": {"actions": ["delete"]}},
{"change": {"actions": ["delete"]}},
{"change": {"actions": ["delete"]}},
{"change": {"actions": ["delete"]}},
{"change": {"actions": ["delete"]}},
{"change": {"actions": ["delete"]}},
{"change": {"actions": ["delete"]}},
{"change": {"actions": ["delete"]}},
{"change": {"actions": ["delete"]}},
{"change": {"actions": ["delete"]}},
{"change": {"actions": ["delete"]}},
{"change": {"actions": ["delete"]}},
{"change": {"actions": ["delete"]}},
{"change": {"actions": ["delete"]}},
{"change": {"actions": ["delete"]}},
{"change": {"actions": ["delete"]}},
{"change": {"actions": ["delete"]}},
{"change": {"actions": ["delete"]}},
{"change": {"actions": ["delete"]}},
{"change": {"actions": ["delete"]}},
{"change": {"actions": ["delete"]}},
{"change": {"actions": ["delete"]}},
{"change": {"actions": ["delete"]}},
{"change": {"actions": ["delete"]}},
{"change": {"actions": ["delete"]}},
{"change": {"actions": ["delete"]}},
{"change": {"actions": ["delete"]}},
{"change": {"actions": ["delete"]}},
{"change": {"actions": ["delete"]}},
{"change": {"actions": ["delete"]}},
{"change": {"actions": ["delete"]}},
{"change": {"actions": ["delete"]}},
{"change": {"actions": ["delete"]}},
{"change": {"actions": ["delete"]}},
{"change": {"actions": ["delete"]}},
{"change": {"actions": ["delete"]}},
{"change": {"actions": ["delete"]}},
{"change": {"actions": ["delete"]}},
{"change": {"actions": ["delete"]}},
{"change": {"actions": ["delete"]}},
{"change": {"actions": ["delete"]}},
{"change": {"actions": ["delete"]}},
{"change": {"actions": ["delete"]}},
{"change": {"actions": ["delete"]}},
]},
}
count(warn) == 0 with input as inp
deny["More than 50 changes (51)"] with input as inp
}

# Test case for denying tracked with too many changes.
test_deny_for_tracked_run_with_too_many_changes {

Check failure on line 66 in plan/require-reasonable-commit-size_test.rego

View workflow job for this annotation

GitHub Actions / Regal Check

Max rule length exceeded. To learn more, see: https://docs.styra.com/regal/rules/style/rule-length
inp := {
"spacelift": {"run": {"type": "TRACKED"}},
"terraform": {"resource_changes": [
{"change": {"actions": ["delete"]}},
{"change": {"actions": ["delete"]}},
{"change": {"actions": ["delete"]}},
{"change": {"actions": ["delete"]}},
{"change": {"actions": ["delete"]}},
{"change": {"actions": ["delete"]}},
{"change": {"actions": ["delete"]}},
{"change": {"actions": ["delete"]}},
{"change": {"actions": ["delete"]}},
{"change": {"actions": ["delete"]}},
{"change": {"actions": ["delete"]}},
{"change": {"actions": ["delete"]}},
{"change": {"actions": ["delete"]}},
{"change": {"actions": ["delete"]}},
{"change": {"actions": ["delete"]}},
{"change": {"actions": ["delete"]}},
{"change": {"actions": ["delete"]}},
{"change": {"actions": ["delete"]}},
{"change": {"actions": ["delete"]}},
{"change": {"actions": ["delete"]}},
{"change": {"actions": ["delete"]}},
{"change": {"actions": ["delete"]}},
{"change": {"actions": ["delete"]}},
{"change": {"actions": ["delete"]}},
{"change": {"actions": ["delete"]}},
{"change": {"actions": ["delete"]}},
{"change": {"actions": ["delete"]}},
{"change": {"actions": ["delete"]}},
{"change": {"actions": ["delete"]}},
{"change": {"actions": ["delete"]}},
{"change": {"actions": ["delete"]}},
{"change": {"actions": ["delete"]}},
{"change": {"actions": ["delete"]}},
{"change": {"actions": ["delete"]}},
{"change": {"actions": ["delete"]}},
{"change": {"actions": ["delete"]}},
{"change": {"actions": ["delete"]}},
{"change": {"actions": ["delete"]}},
{"change": {"actions": ["delete"]}},
{"change": {"actions": ["delete"]}},
{"change": {"actions": ["delete"]}},
{"change": {"actions": ["delete"]}},
{"change": {"actions": ["delete"]}},
{"change": {"actions": ["delete"]}},
{"change": {"actions": ["delete"]}},
{"change": {"actions": ["delete"]}},
{"change": {"actions": ["delete"]}},
{"change": {"actions": ["delete"]}},
{"change": {"actions": ["delete"]}},
{"change": {"actions": ["delete"]}},
{"change": {"actions": ["delete"]}},
]},
}
count(deny) == 0 with input as inp
warn["More than 50 changes (51)"] with input as inp
}

# Test case if no-op changes are included.
test_no_op_changes {

Check failure on line 128 in plan/require-reasonable-commit-size_test.rego

View workflow job for this annotation

GitHub Actions / Regal Check

Max rule length exceeded. To learn more, see: https://docs.styra.com/regal/rules/style/rule-length
inp := {
"spacelift": {"run": {"type": "TRACKED"}},
"terraform": {"resource_changes": [
{"change": {"actions": ["no-op"]}},
{"change": {"actions": ["delete"]}},
{"change": {"actions": ["delete"]}},
{"change": {"actions": ["delete"]}},
{"change": {"actions": ["delete"]}},
{"change": {"actions": ["delete"]}},
{"change": {"actions": ["delete"]}},
{"change": {"actions": ["delete"]}},
{"change": {"actions": ["delete"]}},
{"change": {"actions": ["delete"]}},
{"change": {"actions": ["delete"]}},
{"change": {"actions": ["delete"]}},
{"change": {"actions": ["delete"]}},
{"change": {"actions": ["delete"]}},
{"change": {"actions": ["delete"]}},
{"change": {"actions": ["delete"]}},
{"change": {"actions": ["delete"]}},
{"change": {"actions": ["delete"]}},
{"change": {"actions": ["delete"]}},
{"change": {"actions": ["delete"]}},
{"change": {"actions": ["delete"]}},
{"change": {"actions": ["delete"]}},
{"change": {"actions": ["delete"]}},
{"change": {"actions": ["delete"]}},
{"change": {"actions": ["delete"]}},
{"change": {"actions": ["delete"]}},
{"change": {"actions": ["delete"]}},
{"change": {"actions": ["delete"]}},
{"change": {"actions": ["delete"]}},
{"change": {"actions": ["delete"]}},
{"change": {"actions": ["delete"]}},
{"change": {"actions": ["delete"]}},
{"change": {"actions": ["delete"]}},
{"change": {"actions": ["delete"]}},
{"change": {"actions": ["delete"]}},
{"change": {"actions": ["delete"]}},
{"change": {"actions": ["delete"]}},
{"change": {"actions": ["delete"]}},
{"change": {"actions": ["delete"]}},
{"change": {"actions": ["delete"]}},
{"change": {"actions": ["delete"]}},
{"change": {"actions": ["delete"]}},
{"change": {"actions": ["delete"]}},
{"change": {"actions": ["delete"]}},
{"change": {"actions": ["delete"]}},
{"change": {"actions": ["delete"]}},
{"change": {"actions": ["delete"]}},
{"change": {"actions": ["delete"]}},
{"change": {"actions": ["delete"]}},
{"change": {"actions": ["delete"]}},
{"change": {"actions": ["delete"]}},
]},
}
count(deny) == 0 with input as inp
count(warn) == 0 with input as inp
}

# Test case tracked run for no warning for reasonable commit.
test_no_warn_for_tracked_run_with_reasonable_commit {
inp := {
"spacelift": {"run": {"type": "TRACKED"}},
"terraform": {"resource_changes": [{"change": {"actions": ["delete"]}}]},
}
count(deny) == 0 with input as inp
count(warn) == 0 with input as inp
}

# Test case tracked run for no denying for reasonable commit.
test_no_deny_for_proposed_run_with_reasonable_commit {
inp := {
"spacelift": {"run": {"type": "PROPOSED"}},
"terraform": {"resource_changes": [{"change": {"actions": ["delete"]}}]},
}
count(deny) == 0 with input as inp
count(warn) == 0 with input as inp
}

0 comments on commit 986853d

Please sign in to comment.