docker-tidy/dockertidy/test/unit/test_autostop.py

49 lines
1.2 KiB
Python
Raw Normal View History

2020-03-13 22:39:33 +00:00
"""Test Autostop class."""
import pytest
2020-11-16 00:02:32 +00:00
import docker
from dockertidy import autostop
2020-03-13 22:39:33 +00:00
pytest_plugins = [
"dockertidy.test.fixtures.fixtures",
2020-03-13 22:39:33 +00:00
]
@pytest.fixture
def autostop_fixture(mocker):
2020-03-16 19:12:55 +00:00
mocker.patch.object(
autostop.AutoStop,
2020-03-16 19:12:55 +00:00
"_get_docker_client",
return_value=mocker.create_autospec(docker.APIClient)
)
stop = autostop.AutoStop()
2020-03-13 22:39:33 +00:00
return stop
def test_stop_container(autostop_fixture, mocker):
2020-03-13 22:39:33 +00:00
client = mocker.create_autospec(docker.APIClient)
cid = "asdb"
autostop_fixture._stop_container(client, cid)
2020-03-13 22:39:33 +00:00
client.stop.assert_called_once_with(cid)
def test_build_container_matcher(autostop_fixture, mocker):
2020-03-13 22:39:33 +00:00
prefixes = ["one_", "two_"]
matcher = autostop_fixture._build_container_matcher(prefixes)
2020-03-13 22:39:33 +00:00
assert matcher("one_container")
assert matcher("two_container")
assert not matcher("three_container")
assert not matcher("one")
def test_has_been_running_since_true(autostop_fixture, container, later_time):
assert autostop_fixture._has_been_running_since(container, later_time)
2020-03-13 22:39:33 +00:00
def test_has_been_running_since_false(autostop_fixture, container, earlier_time):
assert not autostop_fixture._has_been_running_since(container, earlier_time)