mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-05-06 13:22:48 +00:00
conditional: fix direct boolean "shortcut" (#47941)
* conditional: fix direct boolean "shortcut" * Add unit tests
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
|
||||
from units.compat import unittest
|
||||
from units.mock.loader import DictDataLoader
|
||||
from units.compat.mock import MagicMock
|
||||
|
||||
from ansible.plugins.strategy import SharedPluginLoaderObj
|
||||
from ansible.template import Templar
|
||||
@@ -33,6 +34,20 @@ class TestConditional(unittest.TestCase):
|
||||
ret = self._eval_con(when, {})
|
||||
self.assertTrue(ret)
|
||||
|
||||
def test_true_boolean(self):
|
||||
self.cond.when = [True]
|
||||
m = MagicMock()
|
||||
ret = self.cond.evaluate_conditional(m, {})
|
||||
self.assertTrue(ret)
|
||||
self.assertFalse(m.is_template.called)
|
||||
|
||||
def test_false_boolean(self):
|
||||
self.cond.when = [False]
|
||||
m = MagicMock()
|
||||
ret = self.cond.evaluate_conditional(m, {})
|
||||
self.assertFalse(ret)
|
||||
self.assertFalse(m.is_template.called)
|
||||
|
||||
def test_undefined(self):
|
||||
when = [u"{{ some_undefined_thing }}"]
|
||||
self.assertRaisesRegexp(errors.AnsibleError, "The conditional check '{{ some_undefined_thing }}' failed",
|
||||
|
||||
Reference in New Issue
Block a user