summaryrefslogtreecommitdiffstats
path: root/test/TestComparisonToEmptyString.py
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--test/TestComparisonToEmptyString.py39
1 files changed, 39 insertions, 0 deletions
diff --git a/test/TestComparisonToEmptyString.py b/test/TestComparisonToEmptyString.py
new file mode 100644
index 0000000..cdbd0fa
--- /dev/null
+++ b/test/TestComparisonToEmptyString.py
@@ -0,0 +1,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))