Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add test for new read_host_from_playbook function
Browse files Browse the repository at this point in the history
PaulFarault committed Feb 9, 2024
1 parent 37a7e71 commit 3161414
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions tdp/core/test_collection.py
Original file line number Diff line number Diff line change
@@ -11,8 +11,10 @@
MissingMandatoryDirectoryError,
PathDoesNotExistsError,
PathIsNotADirectoryError,
read_host_from_playbook,
)
from tdp.core.constants import DAG_DIRECTORY_NAME
from tdp.core.models.test_deployment_log import MockInventoryReader


def test_collection_from_path_does_not_exist():
@@ -50,3 +52,25 @@ def test_collection_from_path(tmp_path_factory: pytest.TempPathFactory):
assert collection_path / DAG_DIRECTORY_NAME / "service.yml" in collection.dag_yamls
assert "service_install" in collection.playbooks
assert "service_config" in collection.playbooks


def test_read_host_from_playbook(tmp_path: Path):
# Create a temporary playbook file
playbook_path = tmp_path / "playbook.yml"
playbook_path.write_text(
"""---
- name: Play 1
hosts: host1, host2
tasks:
- name: Task 1
command: echo "Hello, World!"
"""
)

# Call the function under test
hosts = read_host_from_playbook(
playbook_path, MockInventoryReader(["host1", "host2"])
)

# Assert the expected result
assert hosts == {"host1", "host2"}

0 comments on commit 3161414

Please sign in to comment.