def test_get_docker_path_in_docker_no_substring(in_docker): binds_list = [{'Source': '/opt/my_code', 'Destination': '/project'}] docker_out = json.dumps([{'Mounts': binds_list}]).encode() with _linux_commonpath(), _docker_output(docker_out): path = '/projectSuffix/test/something' assert docker._get_docker_path(path) == path
def test_get_docker_path_in_docker_windows(in_docker): binds_list = [{'Source': r'c:\users\user', 'Destination': r'c:\folder'}] docker_out = json.dumps([{'Mounts': binds_list}]).encode() with _nt_commonpath(), _docker_output(docker_out): path = r'c:\folder\test\something' expected = r'c:\users\user\test\something' assert docker._get_docker_path(path) == expected
def test_get_docker_path_in_docker_binds_path_many_binds(in_docker): binds_list = [ {'Source': '/something_random', 'Destination': '/not-related'}, {'Source': '/opt/my_code', 'Destination': '/project'}, {'Source': '/something-random-2', 'Destination': '/not-related-2'}, ] docker_out = json.dumps([{'Mounts': binds_list}]).encode() with _linux_commonpath(), _docker_output(docker_out): assert docker._get_docker_path('/project') == '/opt/my_code'
def test_get_docker_path_not_in_docker_returns_same(): with mock.patch.object(docker, '_is_in_docker', return_value=False): assert docker._get_docker_path('abc') == 'abc'
def test_get_docker_path_in_docker_docker_in_docker(in_docker): # won't be able to discover "self" container in true docker-in-docker err = CalledProcessError(1, (), 0, b'', b'') with mock.patch.object(docker, 'cmd_output_b', side_effect=err): assert docker._get_docker_path('/project') == '/project'
def test_get_docker_path_in_docker_binds_path_equal(in_docker): binds_list = [{'Source': '/opt/my_code', 'Destination': '/project'}] docker_out = json.dumps([{'Mounts': binds_list}]).encode() with _linux_commonpath(), _docker_output(docker_out): assert docker._get_docker_path('/project') == '/opt/my_code'
def test_get_docker_path_in_docker_no_binds_same_path(in_docker): docker_out = json.dumps([{'Mounts': []}]).encode() with _docker_output(docker_out): assert docker._get_docker_path('abc') == 'abc'