From bc0c4b714509862efcb20df82e11eca1e628a90d Mon Sep 17 00:00:00 2001 From: Tristan Van Berkom Date: Fri, 2 Mar 2018 21:01:51 +0900 Subject: tests/integration/shell.py: Updated shell tests 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 o Updated names of the `host-files` mount specification members o Test the new `optional` feature of the mount specifications --- tests/integration/shell.py | 66 ++++++++++++++++++++++++---------------------- 1 file changed, 34 insertions(+), 32 deletions(-) diff --git a/tests/integration/shell.py b/tests/integration/shell.py index 08dda0d22..98e485f41 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) @@ -160,8 +164,8 @@ def test_host_files(cli, tmpdir, datafiles, path): 'shell': { 'host-files': [ { - 'host': ponyfile, - 'sandbox': path + 'host_path': ponyfile, + 'path': path } ] } @@ -183,8 +187,8 @@ def test_isolated_no_mount(cli, tmpdir, datafiles, path): 'shell': { 'host-files': [ { - 'host': ponyfile, - 'sandbox': path + 'host_path': ponyfile, + 'path': path } ] } @@ -194,18 +198,26 @@ def test_isolated_no_mount(cli, tmpdir, datafiles, path): assert result.exit_code != 0 -# Test that bind mounts which specify directories dont get mounted +# Test that we warn about non-existing files on the host if the mount is not +# declared as optional, and that there is no warning if it is optional +@pytest.mark.parametrize("optional", [("mandatory"), ("optional")]) @pytest.mark.datafiles(DATA_DIR) -def test_host_files_refuse_dir(cli, tmpdir, datafiles): +def test_host_files_missing(cli, tmpdir, datafiles, optional): project = os.path.join(datafiles.dirname, datafiles.basename) - ponydir = os.path.join(project, 'files', 'shell-mount') + ponyfile = os.path.join(project, 'files', 'shell-mount', 'horsy.txt') + + if optional == "optional": + option = True + else: + option = False create_project_conf(project, { 'shell': { 'host-files': [ { - 'host': ponydir, - 'sandbox': '/usr/share/pony' + 'host_path': ponyfile, + 'path': '/etc/pony.conf', + 'optional': option } ] } @@ -216,31 +228,21 @@ def test_host_files_refuse_dir(cli, tmpdir, datafiles): 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 + if option: + # Assert that there was no warning about the mount + assert ponyfile not in result.stderr + else: + # Assert that there was a warning about the mount + assert ponyfile in result.stderr -# Test that we warn about non-existing files on the host, but execute the shell anyway +# 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_host_files_non_existing(cli, tmpdir, datafiles): +def test_cli_mount(cli, tmpdir, datafiles, path): project = os.path.join(datafiles.dirname, datafiles.basename) - ponyfile = os.path.join(project, 'files', 'shell-mount', 'horsy.txt') - - create_project_conf(project, { - 'shell': { - 'host-files': [ - { - 'host': ponyfile, - 'sandbox': '/etc/pony.conf' - } - ] - } - }) + ponyfile = os.path.join(project, 'files', 'shell-mount', 'pony.txt') - # Assert that we did successfully run something in the shell anyway - result = execute_shell(cli, project, ['echo', 'Hello']) + result = execute_shell(cli, project, ['cat', path], mount=(ponyfile, path)) assert result.exit_code == 0 - assert result.output == 'Hello\n' - - # Assert that there was some warning about refusing to mount - assert ponyfile in result.stderr + assert result.output == 'pony\n' -- cgit v1.2.1