summaryrefslogtreecommitdiffstats
path: root/test/rules/test_no_relative_paths.py
blob: 6999cbb454f63cb129bb0a3ae59d60cb7eddc2fe (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
"""Tests for no-relative-paths rule."""
from ansiblelint.rules import RulesCollection
from ansiblelint.rules.no_relative_paths import RoleRelativePath
from ansiblelint.testing import RunFromText

FAIL_TASKS = """
- name: Template example
  template:
    src: ../templates/foo.j2
    dest: /etc/file.conf
- name: Copy example
  copy:
    src: ../files/foo.conf
    dest: /etc/foo.conf
# Removed from test suite as module is no longer part of core
# - name: Some win_template example
#   win_template:
#     src: ../win_templates/file.conf.j2
#     dest: file.conf
# - name: Some win_copy example
#   win_copy:
#     src: ../files/foo.conf
#     dest: renamed-foo.conf
"""

SUCCESS_TASKS = """
- name: Content example with no src
  copy:
    content: '# This file was moved to /etc/other.conf'
    dest: /etc/mine.conf
- name: Copy example
  copy:
    src: /home/example/files/foo.conf
    dest: /etc/foo.conf
"""


def test_no_relative_paths_fail() -> None:
    """Negative test for no-relative-paths."""
    collection = RulesCollection()
    collection.register(RoleRelativePath())
    runner = RunFromText(collection)
    results = runner.run_role_tasks_main(FAIL_TASKS)
    assert len(results) == 2


def test_no_relative_paths_success() -> None:
    """Positive test for no-relative-paths."""
    collection = RulesCollection()
    collection.register(RoleRelativePath())
    runner = RunFromText(collection)
    results = runner.run_role_tasks_main(SUCCESS_TASKS)
    assert len(results) == 0