Skip to content

Commit

Permalink
Allow tests to be in 'test' package
Browse files Browse the repository at this point in the history
This is a Styra DAS convention, and while I'd say `_test` is preferred,
I think it's OK to allow this single exception.

Also update this rule to report end location.

Signed-off-by: Anders Eknert <[email protected]>
  • Loading branch information
anderseknert committed Aug 29, 2024
1 parent afa1ee2 commit 112b2ca
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,14 @@ import data.regal.ast
import data.regal.result

report contains violation if {
not endswith(ast.package_name, "_test")
not _is_test_package(ast.package_name)

some rule in ast.tests

violation := result.fail(rego.metadata.chain(), result.location(rule.head))
violation := result.fail(rego.metadata.chain(), result.ranged_location_from_text(rule.head))
}

_is_test_package(package_name) if endswith(package_name, "_test")

# Styra DAS convention considered OK
_is_test_package("test")
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,13 @@ test_fail_test_outside_test_package if {
"ref": config.docs.resolve_url("$baseUrl/$category/test-outside-test-package", "testing"),
}],
"title": "test-outside-test-package",
"location": {"col": 1, "file": "p_test.rego", "row": 5, "text": `test_foo if { false }`},
"location": {
"col": 1,
"file": "p_test.rego",
"row": 5,
"end": {"col": 9, "row": 5},
"text": `test_foo if { false }`,
},
"level": "error",
}}
}
Expand Down

0 comments on commit 112b2ca

Please sign in to comment.