-
Notifications
You must be signed in to change notification settings - Fork 305
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add show-builtin-errors flag for the verify command (#901)
This is useful to raise config parsing errors when using the parse_config builtins. Previously, the unit test would fail but it was unclear to the user whether that was due to an error in the policy logic or a typo in the config. Signed-off-by: James Alseth <james@jalseth.me>
- Loading branch information
Showing
6 changed files
with
47 additions
and
10 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
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,6 @@ | ||
package main | ||
|
||
deny[{"msg": msg}] { | ||
input.test_field == 123 | ||
msg := "some error" | ||
} |
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,5 @@ | ||
package main | ||
|
||
test_deny_valid { | ||
not deny with input as parse_config_file("file_does_not_exist.yaml") | ||
} |
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,17 @@ | ||
#!/usr/bin/env bats | ||
|
||
@test "Parsing error without show-builtin-errors flag returns test failed" { | ||
run $CONFTEST verify --show-builtin-errors=false | ||
|
||
[ "$status" -eq 1 ] | ||
echo $output | ||
[[ "$output" =~ "1 test, 0 passed, 0 warnings, 1 failure, 0 exceptions, 0 skipped" ]] | ||
} | ||
|
||
@test "Parsing error with show-builtin-errors flag returns builtin error" { | ||
run $CONFTEST verify --show-builtin-errors=true | ||
|
||
[ "$status" -eq 1 ] | ||
echo $output | ||
[[ "$output" =~ "file_does_not_exist.yaml: no such file or directory" ]] | ||
} |