class TestRoleRelativePath(unittest.TestCase): collection = RulesCollection() collection.register(RoleRelativePath()) def setUp(self): self.runner = RunFromText(self.collection) @pytest.mark.xfail( Version(get_dist_version('ansible')) >= Version('2.10.dev0') and Version(get_dist_version('ansible-base')) >= Version('2.10.dev0'), reason='Post-split Ansible Core Engine does not have ' 'the module used in the test playbook.' ' Ref: https://github.com/ansible/ansible-lint/issues/703.' ' Ref: https://github.com/ansible/ansible/pull/68598.', raises=SystemExit, strict=True, ) def test_fail(self): results = self.runner.run_role_tasks_main(FAIL_TASKS) self.assertEqual(4, len(results)) @pytest.mark.xfail( Version(get_dist_version('ansible')) >= Version('2.10.dev0') and Version(get_dist_version('ansible-base')) >= Version('2.10.dev0'), reason='Post-split Ansible Core Engine does not have ' 'the module used in the test playbook.' ' Ref: https://github.com/ansible/ansible-lint/issues/703.' ' Ref: https://github.com/ansible/ansible/pull/68598.', raises=SystemExit, strict=True, ) def test_success(self): results = self.runner.run_role_tasks_main(SUCCESS_TASKS) self.assertEqual(0, len(results))
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))
class TestRoleRelativePath(unittest.TestCase): collection = RulesCollection() collection.register(RoleRelativePath()) def setUp(self): self.runner = RunFromText(self.collection) def test_fail(self): results = self.runner.run_role_tasks_main(FAIL_TASKS) self.assertEqual(4, len(results)) def test_success(self): results = self.runner.run_role_tasks_main(SUCCESS_TASKS) self.assertEqual(0, len(results))
class TestUseHandlerRatherThanWhenChanged(unittest.TestCase): collection = RulesCollection() collection.register(UseHandlerRatherThanWhenChangedRule()) 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_role_tasks_main(FAIL_TASKS) self.assertEqual(5, len(results))
class TestComparisonToEmptyStringRule(unittest.TestCase): collection = RulesCollection() collection.register(ComparisonToEmptyStringRule()) def setUp(self): self.runner = RunFromText(self.collection) def test_compare_when(self): results = self.runner.run_role_tasks_main(PASS_WHEN) self.assertEqual(0, len(results)) def test_compare_is_empty(self): results = self.runner.run_playbook(FAIL_IS_EMPTY) self.assertEqual(1, len(results)) def test_compare_is_not_empty(self): results = self.runner.run_role_tasks_main(FAIL_IS_NOT_EMPTY) self.assertEqual(1, len(results))
class TestRoleRelativePath(unittest.TestCase): collection = RulesCollection() collection.register(RoleRelativePath()) def setUp(self): self.runner = RunFromText(self.collection) def test_role_relative_path(self): results = self.runner.run_role_tasks_main(ROLE_RELATIVE_PATH) self.assertEqual(4, len(results))
class TestLineTooLongRule(unittest.TestCase): collection = RulesCollection() collection.register(LineTooLongRule()) def setUp(self): self.runner = RunFromText(self.collection) def test_long_line(self): results = self.runner.run_role_tasks_main(LONG_LINE) self.assertEqual(1, len(results))
class TestVariableHasSpaces(unittest.TestCase): collection = RulesCollection() collection.register(VariableHasSpacesRule()) def setUp(self): self.runner = RunFromText(self.collection) def test_variable_has_spaces(self): results = self.runner.run_role_tasks_main(TASK_VARIABLES) self.assertEqual(3, len(results))
class TestTaskNoLocalAction(unittest.TestCase): collection = RulesCollection() collection.register(TaskNoLocalAction()) def setUp(self): self.runner = RunFromText(self.collection) def test_local_action(self): results = self.runner.run_role_tasks_main(TASK_LOCAL_ACTION) self.assertEqual(1, len(results))
class TestDeprecatedModuleRule(unittest.TestCase): collection = RulesCollection() collection.register(DeprecatedModuleRule()) def setUp(self): self.runner = RunFromText(self.collection) def test_module_deprecated(self): results = self.runner.run_role_tasks_main(MODULE_DEPRECATED) self.assertEqual(1, len(results))
class TestSkipInsideYaml(unittest.TestCase): rulesdir = os.path.join('lib', 'ansiblelint', 'rules') collection = RulesCollection.create_from_directory(rulesdir) def setUp(self): self.runner = RunFromText(self.collection) def test_role_tasks(self): results = self.runner.run_role_tasks_main(ROLE_TASKS) self.assertEqual(1, len(results)) def test_role_tasks_with_block(self): results = self.runner.run_role_tasks_main(ROLE_TASKS_WITH_BLOCK) self.assertEqual(4, len(results)) def test_playbook(self): results = self.runner.run_playbook(PLAYBOOK) self.assertEqual(7, len(results)) def test_role_meta(self): results = self.runner.run_role_meta_main(ROLE_META) self.assertEqual(0, len(results))
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))
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))
class TestDeprecatedModuleRule(unittest.TestCase): collection = RulesCollection() collection.register(DeprecatedModuleRule()) def setUp(self): self.runner = RunFromText(self.collection) @pytest.mark.xfail( ANSIBLE_MAJOR_VERSION > (2, 9), reason='Ansible devel has changed so ansible-lint needs fixing. ' 'Ref: https://github.com/ansible/ansible-lint/issues/675', raises=SystemExit, strict=True, ) def test_module_deprecated(self): results = self.runner.run_role_tasks_main(MODULE_DEPRECATED) self.assertEqual(1, len(results))
class TestSkipInsideYaml(unittest.TestCase): rulesdir = os.path.join('lib', 'ansiblelint', 'rules') collection = RulesCollection.create_from_directory(rulesdir) def setUp(self): self.runner = RunFromText(self.collection) def test_role_tasks(self): results = self.runner.run_role_tasks_main(ROLE_TASKS) self.assertEqual(5, len(results)) def test_playbook(self): results = self.runner.run_playbook(PLAYBOOK) self.assertEqual(7, len(results)) def test_role_meta(self): results = self.runner.run_role_meta_main(ROLE_META) self.assertEqual(0, len(results))