50 lines
1.2 KiB
Python
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"
|