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 a633af3
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/molecule/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,11 +279,11 @@ 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),
)
return None
return None # pragma: no cover

return galaxy_data

Expand Down
3 changes: 3 additions & 0 deletions tests/fixtures/resources/broken-collection/galaxy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
name: baddies
name_space: acme
version: 1.0.0
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 a633af3

Please sign in to comment.