def test_execute(): my_container = docker.run("busybox:1", ["sleep", "infinity"], detach=True, remove=True) exec_result = docker.execute(my_container, ["echo", "dodo"]) assert exec_result == "dodo" docker.kill(my_container)
def test_restart(): cmd = ["sleep", "infinity"] containers = [docker.run("busybox:1", cmd, detach=True) for _ in range(3)] docker.kill(containers) docker.restart(containers) for container in containers: assert container.state.running
def test_execute_stream(): my_container = docker.run("busybox:1", ["sleep", "infinity"], detach=True, remove=True) exec_result = list( docker.execute(my_container, ["sh", "-c", ">&2 echo dodo"], stream=True)) assert exec_result == [("stderr", b"dodo\n")] docker.kill(my_container)
def test_diff(): my_container = docker.run("busybox:1", ["sleep", "infinity"], detach=True, remove=True) docker.execute(my_container, ["mkdir", "/some_path"]) docker.execute(my_container, ["touch", "/some_file"]) docker.execute(my_container, ["rm", "-rf", "/tmp"]) diff = docker.diff(my_container) assert diff == {"/some_path": "A", "/some_file": "A", "/tmp": "D"} docker.kill(my_container)