diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-14 20:04:50 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-14 20:04:50 +0000 |
commit | 782f8df6e41f29dce2db4970a3ad84aaeb7d8c5f (patch) | |
tree | 3a88a542cd8074743d251881131510157cfc510b /test/TestComparisonToLiteralBool.py | |
parent | Initial commit. (diff) | |
download | ansible-lint-upstream.tar.xz ansible-lint-upstream.zip |
Adding upstream version 4.3.7.upstream/4.3.7upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'test/TestComparisonToLiteralBool.py')
-rw-r--r-- | test/TestComparisonToLiteralBool.py | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/test/TestComparisonToLiteralBool.py b/test/TestComparisonToLiteralBool.py new file mode 100644 index 0000000..041ca1b --- /dev/null +++ b/test/TestComparisonToLiteralBool.py @@ -0,0 +1,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)) |