Skip to content

Commit e8e16e6

Browse files
authored
Merge pull request #109 from olehermanse/next
cfengine lint: Added check for wrong promise block type
2 parents 2003d51 + eb3b6c2 commit e8e16e6

7 files changed

Lines changed: 38 additions & 16 deletions

File tree

src/cfengine_cli/lint.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -609,6 +609,11 @@ def _lint_block_type(node: Node, state: State, location: str, syntax_data: Synta
609609
f"Error: Bundle type must be one of ({', '.join(syntax_data.BUILTIN_BUNDLE_TYPES)}), not '{_text(node)}' {location}",
610610
node,
611611
)
612+
if node.type == "promise_block_type" and _text(node) != "agent":
613+
raise ValidationError(
614+
f"Error: Promise type must be 'agent', not '{_text(node)}' {location}",
615+
node,
616+
)
612617

613618

614619
def _lint_block_name(node: Node, state: State, location: str, syntax_data: SyntaxData):

tests/lint/004_block_type.cf

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
bundle common my_bundle
2+
{
3+
vars:
4+
"x" string => "value";
5+
}
6+
7+
promise agent my_promise_type
8+
{
9+
path => "/bin/true";
10+
interpreter => "/bin/bash";
11+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
2+
bundle notavalidtype my_bundle
3+
^-----------^
4+
Error: Bundle type must be one of (agent, common, edit_line, edit_xml, monitor, server), not 'notavalidtype' at tests/lint/004_block_type.x.cf:1:8
5+
6+
7+
promise server my_promise_type
8+
^----^
9+
Error: Promise type must be 'agent', not 'server' at tests/lint/004_block_type.x.cf:7:9
10+
FAIL: tests/lint/004_block_type.x.cf (2 errors)
11+
Failure, 2 errors in total.

tests/lint/004_block_type.x.cf

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
bundle notavalidtype my_bundle
2+
{
3+
reports:
4+
"Hello";
5+
}
6+
7+
promise server my_promise_type
8+
{
9+
path => "/bin/true";
10+
interpreter => "/bin/bash";
11+
}

tests/lint/004_bundle_type.cf

Lines changed: 0 additions & 5 deletions
This file was deleted.

tests/lint/004_bundle_type.expected.txt

Lines changed: 0 additions & 6 deletions
This file was deleted.

tests/lint/004_bundle_type.x.cf

Lines changed: 0 additions & 5 deletions
This file was deleted.

0 commit comments

Comments
 (0)