summaryrefslogtreecommitdiffstats
path: root/test/TestMetaMainHasInfo.py
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-14 20:04:50 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-14 20:04:50 +0000
commit782f8df6e41f29dce2db4970a3ad84aaeb7d8c5f (patch)
tree3a88a542cd8074743d251881131510157cfc510b /test/TestMetaMainHasInfo.py
parentInitial commit. (diff)
downloadansible-lint-upstream/4.3.7.tar.xz
ansible-lint-upstream/4.3.7.zip
Adding upstream version 4.3.7.upstream/4.3.7upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'test/TestMetaMainHasInfo.py')
-rw-r--r--test/TestMetaMainHasInfo.py94
1 files changed, 94 insertions, 0 deletions
diff --git a/test/TestMetaMainHasInfo.py b/test/TestMetaMainHasInfo.py
new file mode 100644
index 0000000..757a4df
--- /dev/null
+++ b/test/TestMetaMainHasInfo.py
@@ -0,0 +1,94 @@
+# pylint: disable=preferred-module # FIXME: remove once migrated per GH-725
+import unittest
+
+from ansiblelint.rules import RulesCollection
+from ansiblelint.rules.MetaMainHasInfoRule import MetaMainHasInfoRule
+from ansiblelint.testing import RunFromText
+
+NO_GALAXY_INFO = '''
+author: the author
+description: this meta/main.yml has no galaxy_info
+'''
+
+MISSING_INFO = '''
+galaxy_info:
+ # author: the author
+ description: Testing if meta contains values
+ company: Not applicable
+
+ license: MIT
+
+ # min_ansible_version: 2.5
+
+ platforms:
+ - name: Fedora
+ versions:
+ - 25
+ - missing_name: No name
+ versions:
+ - 25
+'''
+
+BAD_TYPES = '''
+galaxy_info:
+ author: 007
+ description: ['Testing meta']
+ company: Not applicable
+
+ license: MIT
+
+ min_ansible_version: 2.5
+
+ platforms: Fedora
+'''
+
+PLATFORMS_LIST_OF_STR = '''
+galaxy_info:
+ author: '007'
+ description: 'Testing meta'
+ company: Not applicable
+
+ license: MIT
+
+ min_ansible_version: 2.5
+
+ platforms: ['Fedora', 'EL']
+'''
+
+
+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) == 1
+ self.assertIn("Platforms should be a list of dictionaries",
+ str(results))