Beispiel #1
0
def test_setup_container_created_not_running(counter, config, docker_client):
    # 'docker create' was somewhen called
    config["global"]["container_id"] = "abcd"
    config.write()

    flexmock(exec_).should_receive("_container_state").with_args(docker_client, "abcd").and_return(
        exec_._NOT_RUNNING
    ).and_return(exec_._RUNNING)

    docker_client.should_receive("start").once()

    result = exec_._setup_container(counter, config, docker_client)
    assert result == "abcd"
Beispiel #2
0
def test_setup_container_in_use(counter, config, docker_client):
    # concurrent instance already running
    with counter:
        counter.incr()

    config["global"]["container_id"] = "abcd"
    config.write()

    result = exec_._setup_container(counter, config, docker_client)
    assert result == "abcd"

    with counter:
        assert counter._get_value() == 2
Beispiel #3
0
def test_setup_container_first_time(counter, config, docker_client):
    # like in a fresh environment
    flexmock(exec_).should_receive("_container_state").and_return(exec_._NOT_CREATED).and_return(
        exec_._NOT_RUNNING
    ).and_return(exec_._RUNNING)

    flexmock(exec_).should_receive("_create_container").and_return("abcd")

    docker_client.should_receive("start").once()

    result = exec_._setup_container(counter, config, docker_client)
    assert result == "abcd"

    config.reload()
    assert config["global"]["container_id"] == "abcd"