blob: 041ca1b3d37ffd060811f4db76f2fd74e56f4ee5 (
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
|
# pylint: disable=preferred-module # FIXME: remove once migrated per GH-725
import unittest
from ansiblelint.rules import RulesCollection
from ansiblelint.rules.ComparisonToLiteralBoolRule import ComparisonToLiteralBoolRule
from ansiblelint.testing import RunFromText
PASS_WHEN = '''
- name: example task
debug:
msg: test
when: my_var
'''
PASS_WHEN_NOT_FALSE = '''
- name: example task
debug:
msg: test
when: not my_var
'''
PASS_WHEN_NOT_NULL = '''
- name: example task
debug:
msg: test
when: my_var not None
'''
FAIL_LITERAL_TRUE = '''
- name: example task
debug:
msg: test
when: my_var == True
'''
FAIL_LITERAL_FALSE = '''
- name: example task
debug:
msg: test
when: my_var == false
'''
class TestComparisonToLiteralBoolRule(unittest.TestCase):
collection = RulesCollection()
collection.register(ComparisonToLiteralBoolRule())
def setUp(self):
self.runner = RunFromText(self.collection)
def test_when(self):
results = self.runner.run_role_tasks_main(PASS_WHEN)
self.assertEqual(0, len(results))
def test_when_not_false(self):
results = self.runner.run_role_tasks_main(PASS_WHEN_NOT_FALSE)
self.assertEqual(0, len(results))
def test_when_not_null(self):
results = self.runner.run_role_tasks_main(PASS_WHEN_NOT_NULL)
self.assertEqual(0, len(results))
def test_literal_true(self):
results = self.runner.run_role_tasks_main(FAIL_LITERAL_TRUE)
self.assertEqual(1, len(results))
def test_literal_false(self):
results = self.runner.run_role_tasks_main(FAIL_LITERAL_FALSE)
self.assertEqual(1, len(results))
|