|
| 1 | +package regal.notices_test |
| 2 | + |
| 3 | +import data.regal.notices |
| 4 | + |
| 5 | +test_promoted_notices_with_level_error if { |
| 6 | + result := notices.promoted_notices with data.regal.rules.imports["use-rego-v1"].notices as {_example_notice} |
| 7 | + with data.internal.user_config as {"rules": {"imports": {"use-rego-v1": {"level": "error"}}}} |
| 8 | + |
| 9 | + # With user config level set to error, the severity should be promoted to error |
| 10 | + result.imports["use-rego-v1"] == {object.union(_example_notice, {"severity": "error"})} |
| 11 | +} |
| 12 | + |
| 13 | +test_promoted_notices_with_level_ignore if { |
| 14 | + result := notices.promoted_notices with data.regal.rules.imports["use-rego-v1"].notices as {_example_notice} |
| 15 | + with data.internal.user_config as {"rules": {"imports": {"use-rego-v1": {"level": "ignore"}}}} |
| 16 | + |
| 17 | + # With user config level set to ignore, the severity should stay none |
| 18 | + result.imports["use-rego-v1"] == {_example_notice} |
| 19 | +} |
| 20 | + |
| 21 | +test_promoted_notices_with_level_warning if { |
| 22 | + result := notices.promoted_notices with data.regal.rules.imports["use-rego-v1"].notices as {_example_notice} |
| 23 | + with data.internal.user_config as {"rules": {"imports": {"use-rego-v1": {"level": "warning"}}}} |
| 24 | + |
| 25 | + # With user config level set to warning, the severity should be promoted to warning |
| 26 | + result.imports["use-rego-v1"] == {object.union(_example_notice, {"severity": "warning"})} |
| 27 | +} |
| 28 | + |
| 29 | +test_promoted_notices_configured_without_level if { |
| 30 | + # Rule is configured but level field is not present |
| 31 | + result := notices.promoted_notices with data.regal.rules.imports["use-rego-v1"].notices as {_example_notice} |
| 32 | + with data.internal.user_config as {"rules": {"imports": {"use-rego-v1": {}}}} |
| 33 | + |
| 34 | + # When configured without level, should default to error |
| 35 | + result.imports["use-rego-v1"] == {object.union(_example_notice, {"severity": "error"})} |
| 36 | +} |
| 37 | + |
| 38 | +test_promoted_notices_mixed_configured_and_unconfigured if { |
| 39 | + notice_configured_rule := { |
| 40 | + "category": "imports", |
| 41 | + "description": "Configured rule", |
| 42 | + "level": "notice", |
| 43 | + "title": "use-rego-v1", |
| 44 | + "severity": "none", |
| 45 | + } |
| 46 | + |
| 47 | + notice_unconfigured_rule := { |
| 48 | + "category": "bugs", |
| 49 | + "description": "Unconfigured rule", |
| 50 | + "level": "notice", |
| 51 | + "title": "deprecated-builtin", |
| 52 | + "severity": "none", |
| 53 | + } |
| 54 | + |
| 55 | + result := notices.promoted_notices with data.regal.rules.imports["use-rego-v1"].notices as {notice_configured_rule} |
| 56 | + with data.regal.rules.bugs["deprecated-builtin"].notices as {notice_unconfigured_rule} |
| 57 | + with data.internal.user_config as {"rules": {"imports": {"use-rego-v1": {"level": "error"}}}} |
| 58 | + |
| 59 | + # Configured rule should have severity promoted to error |
| 60 | + result.imports["use-rego-v1"] == {object.union(notice_configured_rule, {"severity": "error"})} |
| 61 | + |
| 62 | + # Unconfigured rule should keep original severity: none |
| 63 | + result.bugs["deprecated-builtin"] == {notice_unconfigured_rule} |
| 64 | +} |
| 65 | + |
| 66 | +_example_notice := { |
| 67 | + "category": "imports", |
| 68 | + "description": "Test rule description", |
| 69 | + "level": "notice", |
| 70 | + "title": "use-rego-v1", |
| 71 | + "severity": "none", |
| 72 | +} |
0 commit comments