rule-id-filter
Tests how a rule is read and applied: severity, scope, options and switching rules off.
Our implementation passes this case when its check --json output for the input below equals the expected
output.
Input
nodes/a.md---
id: a
type: svc
---nodes/b.md---
id: b
type: svc
---nodes/c.md---
id: c
type: svc
---nodes/r1.md---
id: r1
type: rule
fields:
statement: s
applies_to: {id: a}
check: {require_fields: [owner]}
---nodes/r2.md---
id: r2
type: rule
fields:
statement: s
applies_to: {id: [b, c, zzz, 7]}
check: {require_fields: [owner]}
---nodes/r3.md---
id: r3
type: rule
fields:
statement: s
applies_to: {id: zzz}
check: {require_fields: [owner]}
---nodes/r4.md---
id: r4
type: rule
fields:
statement: s
applies_to: {id: 5}
check: {require_fields: [owner]}
---nodes/r5.md---
id: r5
type: rule
fields:
statement: s
applies_to: {id: a, type: other}
check: {require_fields: [owner]}
---nodes/r6.md---
id: r6
type: rule
fields:
statement: s
enabled: false
applies_to: {id: zzz}
check: {require_fields: [owner]}
---nodes/r7.md---
id: r7
type: rule
fields:
statement: s
applies_to: {id: r1}
check: {require_fields: [owner]}
---Expected output
0 ghosts · 0 load errors · 10 nodes · 3 results
expected.json{
"ghosts": [],
"load_errors": [],
"nodes": [
{
"body": "",
"fields": {},
"id": "a",
"links": [],
"parent": null,
"plane": null,
"title": "a",
"type": "svc"
},
{
"body": "",
"fields": {},
"id": "b",
"links": [],
"parent": null,
"plane": null,
"title": "b",
"type": "svc"
},
{
"body": "",
"fields": {},
"id": "c",
"links": [],
"parent": null,
"plane": null,
"title": "c",
"type": "svc"
},
{
"body": "",
"fields": {
"applies_to": {
"id": "a"
},
"check": {
"require_fields": [
"owner"
]
},
"statement": "s"
},
"id": "r1",
"links": [],
"parent": null,
"plane": null,
"title": "r1",
"type": "rule"
},
{
"body": "",
"fields": {
"applies_to": {
"id": [
"b",
"c",
"zzz",
7
]
},
"check": {
"require_fields": [
"owner"
]
},
"statement": "s"
},
"id": "r2",
"links": [],
"parent": null,
"plane": null,
"title": "r2",
"type": "rule"
},
{
"body": "",
"fields": {
"applies_to": {
"id": "zzz"
},
"check": {
"require_fields": [
"owner"
]
},
"statement": "s"
},
"id": "r3",
"links": [],
"parent": null,
"plane": null,
"title": "r3",
"type": "rule"
},
{
"body": "",
"fields": {
"applies_to": {
"id": 5
},
"check": {
"require_fields": [
"owner"
]
},
"statement": "s"
},
"id": "r4",
"links": [],
"parent": null,
"plane": null,
"title": "r4",
"type": "rule"
},
{
"body": "",
"fields": {
"applies_to": {
"id": "a",
"type": "other"
},
"check": {
"require_fields": [
"owner"
]
},
"statement": "s"
},
"id": "r5",
"links": [],
"parent": null,
"plane": null,
"title": "r5",
"type": "rule"
},
{
"body": "",
"fields": {
"applies_to": {
"id": "zzz"
},
"check": {
"require_fields": [
"owner"
]
},
"enabled": false,
"statement": "s"
},
"id": "r6",
"links": [],
"parent": null,
"plane": null,
"title": "r6",
"type": "rule"
},
{
"body": "",
"fields": {
"applies_to": {
"id": "r1"
},
"check": {
"require_fields": [
"owner"
]
},
"statement": "s"
},
"id": "r7",
"links": [],
"parent": null,
"plane": null,
"title": "r7",
"type": "rule"
}
],
"results": [
{
"node": "a",
"rule": "r1",
"severity": "warn",
"status": "fail"
},
{
"node": "b",
"rule": "r2",
"severity": "warn",
"status": "fail"
},
{
"node": "c",
"rule": "r2",
"severity": "warn",
"status": "fail"
}
],
"structure": {
"errors": [],
"warnings": [
{
"kind": "rule_matches_nothing",
"node": "r3",
"ref": null
},
{
"kind": "rule_matches_nothing",
"node": "r4",
"ref": null
},
{
"kind": "rule_matches_nothing",
"node": "r5",
"ref": null
},
{
"kind": "rule_matches_nothing",
"node": "r7",
"ref": null
}
]
}
}