1
0
mirror of https://github.com/home-assistant/supervisor.git synced 2026-03-01 14:05:34 +00:00
Files
supervisor/tests/resolution/evaluation/test_evaluate_docker_configuration.py
Mike Degatano a122b5f1e9 Migrate info, events and container logs to aiodocker (#6514)
* Migrate info and events to aiodocker

* Migrate container logs to aiodocker

* Fix dns plugin loop test

* Fix mocking for docker info

* Fixes from feedback

* Harden monitor error handling

* Deleted failing tests because they were not useful
2026-02-03 18:36:41 +01:00

73 lines
2.5 KiB
Python

"""Test evaluation base."""
# pylint: disable=import-error,protected-access
from dataclasses import replace
from unittest.mock import patch
from supervisor.const import CoreState
from supervisor.coresys import CoreSys
from supervisor.resolution.evaluations.docker_configuration import (
EXPECTED_LOGGING,
EXPECTED_STORAGE,
EvaluateDockerConfiguration,
)
async def test_evaluation(coresys: CoreSys):
"""Test evaluation."""
docker_configuration = EvaluateDockerConfiguration(coresys)
await coresys.core.set_state(CoreState.INITIALIZE)
assert docker_configuration.reason not in coresys.resolution.unsupported
coresys.docker._info = replace(
coresys.docker.info, storage="unsupported", logging=EXPECTED_LOGGING
)
await docker_configuration()
assert docker_configuration.reason in coresys.resolution.unsupported
coresys.resolution.unsupported.clear()
coresys.docker._info = replace(
coresys.docker.info, storage=EXPECTED_STORAGE[0], logging="unsupported"
)
await docker_configuration()
assert docker_configuration.reason in coresys.resolution.unsupported
coresys.resolution.unsupported.clear()
coresys.docker._info = replace(
coresys.docker.info, storage="overlay2", logging=EXPECTED_LOGGING
)
await docker_configuration()
assert docker_configuration.reason not in coresys.resolution.unsupported
coresys.docker._info = replace(
coresys.docker.info, storage="overlayfs", logging=EXPECTED_LOGGING
)
await docker_configuration()
assert docker_configuration.reason not in coresys.resolution.unsupported
async def test_did_run(coresys: CoreSys):
"""Test that the evaluation ran as expected."""
docker_configuration = EvaluateDockerConfiguration(coresys)
should_run = docker_configuration.states
should_not_run = [state for state in CoreState if state not in should_run]
assert len(should_run) != 0
assert len(should_not_run) != 0
with patch(
"supervisor.resolution.evaluations.docker_configuration.EvaluateDockerConfiguration.evaluate",
return_value=None,
) as evaluate:
for state in should_run:
await coresys.core.set_state(state)
await docker_configuration()
evaluate.assert_called_once()
evaluate.reset_mock()
for state in should_not_run:
await coresys.core.set_state(state)
await docker_configuration()
evaluate.assert_not_called()
evaluate.reset_mock()