This repository has been archived on 2024-06-02. You can view files and clone it, but cannot push or open issues or pull requests.
spud-py/tests/test_podman_manager.py
Marc Cataford 17781b0eb9
All checks were successful
/ Static Analysis (push) Successful in 1m5s
/ Tests (push) Successful in 52s
feat: add status command to query the basic status meta of services
2024-04-14 00:27:55 -04:00

50 lines
1.2 KiB
Python

import json
import os
import typing
import pytest
from spud.container_managers import PodmanManager, ServiceMetadata
@pytest.fixture(name="mock_podman")
def mock_podman_fixture(tmpdir, monkeypatch):
def _mock_podman(output: dict[str, typing.Any]):
serialized_output = json.dumps(output)
mock_out_path = tmpdir / "out"
mock_out_path.write(serialized_output)
mock_bin_path = tmpdir / "podman"
mock_bin_path.write(f"#!/bin/bash\ncat {str(tmpdir)}/out")
mock_bin_path.chmod(0o777)
monkeypatch.setenv("PATH", str(tmpdir), prepend=os.pathsep)
return _mock_podman
def test_get_services_returns_metadata_on_services(mock_podman):
manager = PodmanManager()
mock_podman_output = [
{
"Name": "pod1",
"Id": "1",
"Status": "Running",
"Containers": [
{
"Names": "pod1-1",
"Status": "Running",
"Id": "2",
}
],
}
]
mock_podman(mock_podman_output)
services = manager.get_services()
assert len(services) == 1
service = services[0]
assert isinstance(service, ServiceMetadata)
assert service.name == "pod1"