Skip to content

Commit

Permalink
Add test for broken galaxy.yml detection
Browse files Browse the repository at this point in the history
  • Loading branch information
Qalthos committed Dec 13, 2024
1 parent 9adc8b3 commit 90547d2
Show file tree
Hide file tree
Showing 8 changed files with 81 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/molecule/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ def collection(self) -> CollectionData | None:
important_keys = {"name", "namespace"}
if missing_keys := important_keys.difference(galaxy_data.keys()):
LOG.warning(
"The detected galaxy.yml file (%s) is incomplete, missing %s",
"The detected galaxy.yml file (%s) is invalid, missing mandatory field %s",
galaxy_file,
util.oxford_comma(missing_keys),
)
Expand Down
1 change: 1 addition & 0 deletions tests/fixtures/resources/broken-collection/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Changelog
33 changes: 33 additions & 0 deletions tests/fixtures/resources/broken-collection/galaxy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: goodies
name_space: acme
version: 1.0.0
readme: README.md
authors:
- Red Hat
description: Acme Goodies Collection
build_ignore:
- "*.egg-info"
- .DS_Store
- .eggs
- .gitignore
- .mypy_cache
- .pytest_cache
- .stestr
- .stestr.conf
- .tox
- .vscode
- MANIFEST.in
- build
- dist
- doc
- report.html
- setup.cfg
- setup.py
- "tests/unit/*.*"
- README.rst
- tox.ini

repository: https://opendev.org/openstack/tripleo-repos
license_file: LICENSE
tags:
- tools
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
- name: Converge
hosts: localhost
tasks:
- name: "Include sample role from current collection"
ansible.builtin.include_role:
name: acme.goodies.get_rich
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
dependency:
name: galaxy
driver:
name: default
platforms:
- name: instance
provisioner:
name: ansible
verifier:
name: ansible
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
- name: Some task inside foo.bar collection
ansible.builtin.debug:
msg: "hello world!"
24 changes: 24 additions & 0 deletions tests/unit/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,30 @@ def test_collection_property(
assert modified_instance.collection["namespace"] == "acme"


def test_collection_property_broken_collection(
caplog: pytest.LogCaptureFixture,
config_instance: config.Config,
resources_folder_path: Path,
) -> None:
"""Test collection property with a malformed galaxy.yml.
Args:
caplog: pytest log capture fixture.
config_instance: Instance of Config.
resources_folder_path: Path to resources directory holding a valid collection.
"""
modified_instance = copy.copy(config_instance)

# Alter config_instance to start at path of a collection
collection_path = resources_folder_path / "broken-collection"
modified_instance.project_directory = str(collection_path)

assert modified_instance.collection is None

msg = "missing mandatory field 'namespace'"
assert msg in caplog.text


def test_dependency_property(config_instance: config.Config) -> None: # noqa: D103
assert isinstance(config_instance.dependency, ansible_galaxy.AnsibleGalaxy)

Expand Down

0 comments on commit 90547d2

Please sign in to comment.