diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 16:04:56 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 16:04:56 +0000 |
commit | d964cec5e6aa807b75c7a4e7cdc5f11e54b2eda2 (patch) | |
tree | 794bc3738a00b5e599f06d1f2f6d79048d87ff8e /test/rules/test_meta_no_info.py | |
parent | Initial commit. (diff) | |
download | ansible-lint-d964cec5e6aa807b75c7a4e7cdc5f11e54b2eda2.tar.xz ansible-lint-d964cec5e6aa807b75c7a4e7cdc5f11e54b2eda2.zip |
Adding upstream version 6.13.1.upstream/6.13.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'test/rules/test_meta_no_info.py')
-rw-r--r-- | test/rules/test_meta_no_info.py | 98 |
1 files changed, 98 insertions, 0 deletions
diff --git a/test/rules/test_meta_no_info.py b/test/rules/test_meta_no_info.py new file mode 100644 index 0000000..bbadec6 --- /dev/null +++ b/test/rules/test_meta_no_info.py @@ -0,0 +1,98 @@ +"""Tests for meta-no-info rule.""" +from ansiblelint.rules import RulesCollection +from ansiblelint.rules.meta_no_info 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'] +""" + + +def test_no_galaxy_info() -> None: + """Test meta-no-info with missing galaxy_info.""" + collection = RulesCollection() + collection.register(MetaMainHasInfoRule()) + runner = RunFromText(collection) + results = runner.run_role_meta_main(NO_GALAXY_INFO) + assert len(results) == 1 + assert "No 'galaxy_info' found" in str(results) + + +def test_missing_info() -> None: + """Test meta-no-info.""" + collection = RulesCollection() + collection.register(MetaMainHasInfoRule()) + runner = RunFromText(collection) + results = runner.run_role_meta_main(MISSING_INFO) + assert len(results) == 3 + assert "Role info should contain author" in str(results) + assert "Role info should contain min_ansible_version" in str(results) + assert "Platform should contain name" in str(results) + + +def test_bad_types() -> None: + """Test meta-no-info with bad types.""" + collection = RulesCollection() + collection.register(MetaMainHasInfoRule()) + runner = RunFromText(collection) + results = runner.run_role_meta_main(BAD_TYPES) + assert len(results) == 3 + assert "author should be a string" in str(results) + assert "description should be a string" in str(results) + assert "Platforms should be a list of dictionaries" in str(results) + + +def test_platform_list_of_str() -> None: + """Test meta-no-info with platforms.""" + collection = RulesCollection() + collection.register(MetaMainHasInfoRule()) + runner = RunFromText(collection) + results = runner.run_role_meta_main(PLATFORMS_LIST_OF_STR) + assert len(results) == 1 + assert "Platforms should be a list of dictionaries" in str(results) |