summaryrefslogtreecommitdiffstats
path: root/test/test_skip_inside_yaml.py
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 16:04:56 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 16:04:56 +0000
commitd964cec5e6aa807b75c7a4e7cdc5f11e54b2eda2 (patch)
tree794bc3738a00b5e599f06d1f2f6d79048d87ff8e /test/test_skip_inside_yaml.py
parentInitial commit. (diff)
downloadansible-lint-d964cec5e6aa807b75c7a4e7cdc5f11e54b2eda2.tar.xz
ansible-lint-d964cec5e6aa807b75c7a4e7cdc5f11e54b2eda2.zip
Adding upstream version 6.13.1.upstream/6.13.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'test/test_skip_inside_yaml.py')
-rw-r--r--test/test_skip_inside_yaml.py75
1 files changed, 75 insertions, 0 deletions
diff --git a/test/test_skip_inside_yaml.py b/test/test_skip_inside_yaml.py
new file mode 100644
index 0000000..d90c45d
--- /dev/null
+++ b/test/test_skip_inside_yaml.py
@@ -0,0 +1,75 @@
+"""Tests related to use of inline noqa."""
+import pytest
+
+from ansiblelint.rules import RulesCollection
+from ansiblelint.runner import Runner
+from ansiblelint.testing import RunFromText, run_ansible_lint
+
+ROLE_TASKS = """\
+---
+- ansible.builtin.debug:
+ msg: this should fail linting due lack of name
+- ansible.builtin.debug: # noqa: unnamed-task
+ msg: this should pass due to noqa comment
+"""
+
+ROLE_TASKS_WITH_BLOCK = """\
+---
+- name: Bad git 1 # noqa: latest[git]
+ action: ansible.builtin.git a=b c=d
+- name: Bad git 2
+ action: ansible.builtin.git a=b c=d
+- name: Block with rescue and always section
+ block:
+ - name: Bad git 3 # noqa: latest[git]
+ action: ansible.builtin.git a=b c=d
+ - name: Bad git 4
+ action: ansible.builtin.git a=b c=d
+ rescue:
+ - name: Bad git 5 # noqa: latest[git]
+ action: ansible.builtin.git a=b c=d
+ - name: Bad git 6
+ action: ansible.builtin.git a=b c=d
+ always:
+ - name: Bad git 7 # noqa: latest[git]
+ action: ansible.builtin.git a=b c=d
+ - name: Bad git 8
+ action: ansible.builtin.git a=b c=d
+"""
+
+
+def test_role_tasks(default_text_runner: RunFromText) -> None:
+ """Check that role tasks can contain skips."""
+ results = default_text_runner.run_role_tasks_main(ROLE_TASKS)
+ assert len(results) == 1, results
+ assert results[0].linenumber == 2
+ assert results[0].tag == "name[missing]"
+ assert results[0].rule.id == "name"
+
+
+def test_role_tasks_with_block(default_text_runner: RunFromText) -> None:
+ """Check that blocks in role tasks can contain skips."""
+ results = default_text_runner.run_role_tasks_main(ROLE_TASKS_WITH_BLOCK)
+ assert len(results) == 12
+
+
+@pytest.mark.parametrize(
+ ("lintable", "expected"),
+ (pytest.param("examples/playbooks/test_skip_inside_yaml.yml", 10, id="yaml"),),
+)
+def test_inline_skips(
+ default_rules_collection: RulesCollection, lintable: str, expected: int
+) -> None:
+ """Check that playbooks can contain skips."""
+ results = Runner(lintable, rules=default_rules_collection).run()
+
+ assert len(results) == expected
+
+
+def test_role_meta() -> None:
+ """Test running from inside meta folder."""
+ role_path = "examples/roles/meta_noqa"
+
+ result = run_ansible_lint("-v", role_path)
+ assert len(result.stdout) == 0
+ assert result.returncode == 0