Using Severity Levels #2914
-
I wanted to make use of severity levels within the custom rules I'm writing so a pipeline can make a decision at the end of the run to fail, pass or pass with warnings. Obviously using My question is how to leverage this programmatically as I would have thought in a result variable the test wouldn't be a failure but in a Warning result so you could look for it. In this example my Assert-PSRule is using a ResultVariable of if (($validation | Where-Object {$_.Outcome -eq 'Fail'}).Count -eq 0) {
# Success
}
else {
# Failed tests
} Rule example: Rule 'common.found.schema' -Ref 'vaf.config.0002' -Level Warning {
$Assert.HasField($TargetObject, '$schema')
} Output example: [PASS] common.valid.json.configuration (vaf.config.0001)
[FAIL] common.found.schema (vaf.config.0002)
| File: rule_module/test_configs/cluster.version_3_0_0.json:2:125
| REASON:
| - Path $schema: Does not exist.
[PASS] common.found.version (vaf.config.0003) I've referenced - testing-infrastructure In the end I'm trying to replicate behavior I would have used with Pester to set a test result as Inconclusive to generate that soft failure in a validation. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Hi @sapritchard. Thanks for the question. I'm not sure I fully understand the how you are integrating with Pester, but let me try to answer the question. Additionally see: https://microsoft.github.io/PSRule/v2/scenarios/validation-pipeline/validation-pipeline/#calling-from-pester If the object did not pass the condition the rule outcome is There are a few other properties that would be helpful for your case.
The original intent of the rule level is to allow breaking tests based on severity. In PSRule v2, PSRule will generate an error/ warning/ information event to allow the pipeline or tests to terminate. Error being the normal cases when the pipeline would break. This is more configurable in PSRule v3 which allows configuration for breaking the pipeline at a lower level like warning. However this functionality is mostly for the purpose of Assert-PSRule. If you are wrapping in Pester you can read the properties directly and make your own logic. Currently the level is not output specifically in the text output of |
Beta Was this translation helpful? Give feedback.
Hi @sapritchard. Thanks for the question. I'm not sure I fully understand the how you are integrating with Pester, but let me try to answer the question. Additionally see: https://microsoft.github.io/PSRule/v2/scenarios/validation-pipeline/validation-pipeline/#calling-from-pester
If the object did not pass the condition the rule outcome is
Fail
regardless of the level. It can beError
if there was an error generated by the rule withWrite-Error
/ or a bug in the rule that caused an unexpected error.There are a few other properties that would be helpful for your case.
Level
property on the result shows is the level of the rule, which can be combined withOutcome
. i.e. the rule failed …