summaryrefslogtreecommitdiffstats
path: root/test/TestVariableHasSpaces.py
blob: 01b12c9ff8de4dc438863b4779e66925770ba2d3 (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
54
# pylint: disable=preferred-module  # FIXME: remove once migrated per GH-725
import unittest

from ansiblelint.rules import RulesCollection
from ansiblelint.rules.VariableHasSpacesRule import VariableHasSpacesRule
from ansiblelint.testing import RunFromText

TASK_VARIABLES = '''
- name: good variable format
  debug:
    msg: "{{ good_format }}"
- name: good variable format
  debug:
    msg: "Value: {{ good_format }}"
- name: jinja escaping allowed
  debug:
    msg: "{{ '{{' }}"
- name: jinja escaping allowed
  shell: docker info --format '{{ '{{' }}json .Swarm.LocalNodeState{{ '}}' }}' | tr -d '"'
- name: jinja whitespace control allowed
  debug:
    msg: |
      {{ good_format }}/
      {{- good_format }}
      {{- good_format -}}
- name: bad variable format
  debug:
    msg: "{{bad_format}}"
- name: bad variable format
  debug:
    msg: "Value: {{ bad_format}}"
- name: bad variable format
  debug:
    msg: "{{bad_format }}"
- name: not a jinja variable
  debug:
    msg: "test"
  example: "data = ${lookup{$local_part}lsearch{/etc/aliases}}"
- name: JSON inside jinja is valid
  debug:
    msg: "{{ {'test': {'subtest': variable}} }}"
'''


class TestVariableHasSpaces(unittest.TestCase):
    collection = RulesCollection()
    collection.register(VariableHasSpacesRule())

    def setUp(self):
        self.runner = RunFromText(self.collection)

    def test_variable_has_spaces(self):
        results = self.runner.run_role_tasks_main(TASK_VARIABLES)
        self.assertEqual(3, len(results))