def test_docker_custom_image():
    container = DockerContainer("mysql:5.7.17")
    container.with_exposed_ports(3306)
    container.with_env("MYSQL_ROOT_PASSWORD", "root")

    with container:
        port = container.get_exposed_port(3306)
        assert int(port) > 0
def test_container_environments():
    code_dir = Path(__file__).parent
    container = DockerContainer("nginx:latest")
    container.with_env('TEST', 'test')
    container.with_env('DOCKER', 'docker')

    with container:
        output = container.exec("bash -c 'echo $TEST $DOCKER'").output.decode(
            'utf-8').strip()
        assert output == 'test docker'
def test_add_map_entry_override_non_mapping_value():
    code_dir = Path(__file__).parent
    container = DockerContainer("nginx:latest",
                                something='initial-value-is-not-a-map')
    container._with_map_entry('something', 'is', 'arbitrary')
    container._with_map_entry('something', 'also', 'arbitrary')
    container.with_bind_ports(8080, 80)
    container.with_exposed_ports(8000)
    container.with_env('test', 'value')
    container.with_volume_mapping(code_dir, '/code')

    assert container._kwargs['something'] == {
        'also': 'arbitrary',
        'is': 'arbitrary'
    }
    assert container._kwargs['ports'] == {8000: None, 8080: 80}
    assert container._kwargs['environment'] == {'test': 'value'}
    assert container._kwargs['volumes'] == {
        code_dir: {
            'bind': '/code',
            'mode': 'ro'
        }
    }