diff options
author | Tristan Van Berkom <tristan.vanberkom@codethink.co.uk> | 2018-03-02 21:01:51 +0900 |
---|---|---|
committer | Tristan Van Berkom <tristan.vanberkom@codethink.co.uk> | 2018-03-02 21:03:07 +0900 |
commit | d2b80da5166c163296603312378ecde6b01ec0e0 (patch) | |
tree | c98aac660e2686591ae2b8b81f052ae1a351998e | |
parent | 4c13ed238f2b8746f698d1da1ac5bb073dfd9409 (diff) | |
download | buildstream-tristan/shell-mounts.tar.gz |
tests/integration/shell.py: Updated shell teststristan/shell-mounts
o Added new test for `bst shell --mount`
o Removed the test that a directory is refused in `host-files`,
this is no longer a requirement
-rw-r--r-- | tests/integration/shell.py | 44 |
1 files changed, 17 insertions, 27 deletions
diff --git a/tests/integration/shell.py b/tests/integration/shell.py index 08dda0d22..348ee1369 100644 --- a/tests/integration/shell.py +++ b/tests/integration/shell.py @@ -41,10 +41,11 @@ def create_project_conf(project_dir, config): # cli (Cli): The cli runner fixture # project (str): The project directory # command (list): The command argv list +# mount (tuple): A (host, target) tuple for the `--mount` option # element (str): The element to build and run a shell with # isolate (bool): Whether to pass --isolate to `bst shell` # -def execute_shell(cli, project, command, element='base.bst', isolate=False): +def execute_shell(cli, project, command, mount=None, element='base.bst', isolate=False): # Ensure the element is built result = cli.run(project=project, args=['build', element]) assert result.exit_code == 0 @@ -52,6 +53,9 @@ def execute_shell(cli, project, command, element='base.bst', isolate=False): args = ['shell'] if isolate: args += ['--isolate'] + if mount is not None: + host_path, target_path = mount + args += ['--mount', host_path, target_path] args += [element, '--'] + command return cli.run(project=project, args=args) @@ -194,32 +198,6 @@ def test_isolated_no_mount(cli, tmpdir, datafiles, path): assert result.exit_code != 0 -# Test that bind mounts which specify directories dont get mounted -@pytest.mark.datafiles(DATA_DIR) -def test_host_files_refuse_dir(cli, tmpdir, datafiles): - project = os.path.join(datafiles.dirname, datafiles.basename) - ponydir = os.path.join(project, 'files', 'shell-mount') - - create_project_conf(project, { - 'shell': { - 'host-files': [ - { - 'host': ponydir, - 'sandbox': '/usr/share/pony' - } - ] - } - }) - - # Assert that we did successfully run something in the shell anyway - result = execute_shell(cli, project, ['echo', 'Hello']) - assert result.exit_code == 0 - assert result.output == 'Hello\n' - - # Assert that there was some warning about refusing to mount - assert ponydir in result.stderr - - # Test that we warn about non-existing files on the host, but execute the shell anyway @pytest.mark.datafiles(DATA_DIR) def test_host_files_non_existing(cli, tmpdir, datafiles): @@ -244,3 +222,15 @@ def test_host_files_non_existing(cli, tmpdir, datafiles): # Assert that there was some warning about refusing to mount assert ponyfile in result.stderr + + +# Test that bind mounts defined in project.conf work +@pytest.mark.parametrize("path", [("/etc/pony.conf"), ("/usr/share/pony/pony.txt")]) +@pytest.mark.datafiles(DATA_DIR) +def test_cli_mount(cli, tmpdir, datafiles, path): + project = os.path.join(datafiles.dirname, datafiles.basename) + ponyfile = os.path.join(project, 'files', 'shell-mount', 'pony.txt') + + result = execute_shell(cli, project, ['cat', path], mount=(ponyfile, path)) + assert result.exit_code == 0 + assert result.output == 'pony\n' |