From 782f8df6e41f29dce2db4970a3ad84aaeb7d8c5f Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Tue, 14 May 2024 22:04:50 +0200 Subject: Adding upstream version 4.3.7. Signed-off-by: Daniel Baumann --- test/TestSudoRule.py | 67 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 test/TestSudoRule.py (limited to 'test/TestSudoRule.py') diff --git a/test/TestSudoRule.py b/test/TestSudoRule.py new file mode 100644 index 0000000..a105854 --- /dev/null +++ b/test/TestSudoRule.py @@ -0,0 +1,67 @@ +# pylint: disable=preferred-module # FIXME: remove once migrated per GH-725 +import unittest + +from ansiblelint.rules import RulesCollection +from ansiblelint.rules.SudoRule import SudoRule +from ansiblelint.testing import RunFromText + +ROLE_2_ERRORS = ''' +- name: test + debug: + msg: 'test message' + sudo: yes + sudo_user: nobody +''' + +ROLE_0_ERRORS = ''' +- name: test + debug: + msg: 'test message' + become: yes + become_user: somebody +''' + +PLAY_4_ERRORS = ''' +- hosts: all + sudo: yes + sudo_user: somebody + tasks: + - name: test + debug: + msg: 'test message' + sudo: yes + sudo_user: nobody +''' + +PLAY_1_ERROR = ''' +- hosts: all + tasks: + - name: test + debug: + msg: 'test message' + sudo: yes +''' + + +class TestSudoRule(unittest.TestCase): + collection = RulesCollection() + collection.register(SudoRule()) + + def setUp(self): + self.runner = RunFromText(self.collection) + + def test_run_role_fail(self): + results = self.runner.run_role_tasks_main(ROLE_2_ERRORS) + self.assertEqual(2, len(results)) + + def test_run_role_pass(self): + results = self.runner.run_role_tasks_main(ROLE_0_ERRORS) + self.assertEqual(0, len(results)) + + def test_play_root_and_task_fail(self): + results = self.runner.run_playbook(PLAY_4_ERRORS) + self.assertEqual(4, len(results)) + + def test_play_task_fail(self): + results = self.runner.run_playbook(PLAY_1_ERROR) + self.assertEqual(1, len(results)) -- cgit v1.2.3