blob: cdbd0faac3c89bb64678b8c1056d14e1642a1d1e (
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
|
# pylint: disable=preferred-module # FIXME: remove once migrated per GH-725
import unittest
from ansiblelint.rules import RulesCollection
from ansiblelint.rules.ComparisonToEmptyStringRule import ComparisonToEmptyStringRule
from ansiblelint.testing import RunFromText
SUCCESS_TASKS = '''
- name: shut down
command: /sbin/shutdown -t now
when: ansible_os_family
'''
FAIL_TASKS = '''
- hosts: all
tasks:
- name: shut down
command: /sbin/shutdown -t now
when: ansible_os_family == ""
- name: shut down
command: /sbin/shutdown -t now
when: ansible_os_family !=""
'''
class TestComparisonToEmptyStringRule(unittest.TestCase):
collection = RulesCollection()
collection.register(ComparisonToEmptyStringRule())
def setUp(self):
self.runner = RunFromText(self.collection)
def test_success(self):
results = self.runner.run_role_tasks_main(SUCCESS_TASKS)
self.assertEqual(0, len(results))
def test_fail(self):
results = self.runner.run_playbook(FAIL_TASKS)
self.assertEqual(2, len(results))
|