summaryrefslogtreecommitdiffstats
path: root/test/test_skip_playbook_items.py
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-13 12:06:49 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-13 12:06:49 +0000
commit2fe34b6444502079dc0b84365ce82dbc92de308e (patch)
tree8fedcab52bbbc3db6c5aa909a88a7a7b81685018 /test/test_skip_playbook_items.py
parentInitial commit. (diff)
downloadansible-lint-upstream/6.17.2.tar.xz
ansible-lint-upstream/6.17.2.zip
Adding upstream version 6.17.2.upstream/6.17.2
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'test/test_skip_playbook_items.py')
-rw-r--r--test/test_skip_playbook_items.py121
1 files changed, 121 insertions, 0 deletions
diff --git a/test/test_skip_playbook_items.py b/test/test_skip_playbook_items.py
new file mode 100644
index 0000000..2861c6a
--- /dev/null
+++ b/test/test_skip_playbook_items.py
@@ -0,0 +1,121 @@
+"""Tests related to use of noqa inside playbooks."""
+import pytest
+
+from ansiblelint.testing import RunFromText
+
+PLAYBOOK_PRE_TASKS = """\
+---
+- name: Fixture
+ hosts: all
+ tasks:
+ - 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
+ pre_tasks:
+ - 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
+"""
+
+PLAYBOOK_POST_TASKS = """\
+---
+- name: Fixture
+ hosts: all
+ tasks:
+ - 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
+ post_tasks:
+ - 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
+"""
+
+PLAYBOOK_HANDLERS = """\
+---
+- name: Fixture
+ hosts: all
+ tasks:
+ - 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
+ handlers:
+ - 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
+"""
+
+PLAYBOOK_TWO_PLAYS = """\
+---
+- name: Fixture
+ hosts: all
+ tasks:
+ - 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: Fixture 2
+ hosts: all
+ tasks:
+ - 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
+"""
+
+PLAYBOOK_WITH_BLOCK = """\
+---
+- name: Fixture
+ hosts: all
+ tasks:
+ - 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
+"""
+
+
+@pytest.mark.parametrize(
+ ("playbook", "length"),
+ (
+ pytest.param(PLAYBOOK_PRE_TASKS, 6, id="PRE_TASKS"),
+ pytest.param(PLAYBOOK_POST_TASKS, 6, id="POST_TASKS"),
+ pytest.param(PLAYBOOK_HANDLERS, 6, id="HANDLERS"),
+ pytest.param(PLAYBOOK_TWO_PLAYS, 6, id="TWO_PLAYS"),
+ pytest.param(PLAYBOOK_WITH_BLOCK, 12, id="WITH_BLOCK"),
+ ),
+)
+def test_pre_tasks(
+ default_text_runner: RunFromText,
+ playbook: str,
+ length: int,
+) -> None:
+ """Check that skipping is possible in different playbook parts."""
+ # When
+ results = default_text_runner.run_playbook(playbook)
+
+ # Then
+ assert len(results) == length