class TestMetaMainHasInfo(unittest.TestCase): collection = RulesCollection() collection.register(MetaMainHasInfoRule()) def setUp(self): self.runner = RunFromText(self.collection) def test_no_galaxy_info(self): results = self.runner.run_role_meta_main(NO_GALAXY_INFO) assert len(results) == 1 self.assertIn("No 'galaxy_info' found", str(results)) def test_missing_info(self): results = self.runner.run_role_meta_main(MISSING_INFO) assert len(results) == 3 self.assertIn("Role info should contain author", str(results)) self.assertIn("Role info should contain min_ansible_version", str(results)) self.assertIn("Platform should contain name", str(results)) def test_bad_types(self): results = self.runner.run_role_meta_main(BAD_TYPES) assert len(results) == 3 self.assertIn("author should be a string", str(results)) self.assertIn("description should be a string", str(results)) self.assertIn("Platforms should be a list of dictionaries", str(results)) def test_platform_list_of_str(self): results = self.runner.run_role_meta_main(PLATFORMS_LIST_OF_STR) assert len(results) == 2 self.assertIn("Platforms should be a list of dictionaries", str(results))
class TestMetaMainHasInfo(unittest.TestCase): collection = RulesCollection() collection.register(MetaMainHasInfoRule()) def setUp(self): self.runner = RunFromText(self.collection) def test_no_galaxy_info(self): results = self.runner.run_role_meta_main(NO_GALAXY_INFO) self.assertIn("No 'galaxy_info' found", str(results)) def test_missing_info(self): results = self.runner.run_role_meta_main(MISSING_INFO) self.assertIn("Role info should contain author", str(results)) self.assertIn("Role info should contain min_ansible_version", str(results)) self.assertIn("Platform should contain name", str(results))
class TestMetaTagValid(unittest.TestCase): collection = RulesCollection() collection.register(MetaTagValidRule()) def setUp(self): self.runner = RunFromText(self.collection) def test_valid_tag_rule(self): results = self.runner.run_role_meta_main(META_TAG_VALID) self.assertIn("Use 'galaxy_tags' rather than 'categories'", str(results)) self.assertIn("Expected 'categories' to be a list", str(results)) self.assertIn("invalid: 'my s q l'", str(results)) self.assertIn("invalid: 'MYTAG'", str(results))
class TestMetaChangeFromDefault(unittest.TestCase): collection = RulesCollection() collection.register(MetaChangeFromDefaultRule()) def setUp(self): self.runner = RunFromText(self.collection) def test_default_galaxy_info(self): results = self.runner.run_role_meta_main(DEFAULT_GALAXY_INFO) self.assertIn("Should change default metadata: author", str(results)) self.assertIn("Should change default metadata: description", str(results)) self.assertIn("Should change default metadata: company", str(results)) self.assertIn("Should change default metadata: license", str(results))
class TestMetaVideoLinks(unittest.TestCase): collection = RulesCollection() collection.register(MetaVideoLinksRule()) def setUp(self): self.runner = RunFromText(self.collection) def test_video_links(self): results = self.runner.run_role_meta_main(META_VIDEO_LINKS) self.assertIn("Expected item in 'video_links' to be a dictionary", str(results)) self.assertIn("'video_links' to contain only keys 'url' and 'title'", str(results)) self.assertIn("URL format 'www.myvid.com/vid' is not recognized", str(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))
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(8, len(results)) def test_role_meta(self): results = self.runner.run_role_meta_main(ROLE_META) self.assertEqual(0, len(results))
class TestSkipInsideYaml(unittest.TestCase): rulesdir = os.path.join('lib', 'ansiblelint', 'rules') collection = RulesCollection([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))