summaryrefslogtreecommitdiff
path: root/tests/frontend/artifact_show.py
diff options
context:
space:
mode:
authorTristan Van Berkom <tristan.van.berkom@gmail.com>2020-11-20 08:04:52 +0000
committerTristan Van Berkom <tristan.van.berkom@gmail.com>2020-11-20 08:04:52 +0000
commit9eee3353a9342ff697e0260ffa58700b857b6288 (patch)
tree3625ffa9c9faa1f963473ac46f6bfdf7cee46289 /tests/frontend/artifact_show.py
parentf6ee38f5b61073b27b94f0fecb8258dc942f5ddd (diff)
parent84e964af45ae9faf2e3d8309eba3a31f58c5b7b9 (diff)
downloadbuildstream-9eee3353a9342ff697e0260ffa58700b857b6288.tar.gz
Merge branch 'tristan/fix-glob-handling' into 'master'
Fix glob handling in the CLI Closes #959 See merge request BuildStream/buildstream!2102
Diffstat (limited to 'tests/frontend/artifact_show.py')
-rw-r--r--tests/frontend/artifact_show.py67
1 files changed, 67 insertions, 0 deletions
diff --git a/tests/frontend/artifact_show.py b/tests/frontend/artifact_show.py
index de9b78c45..ebea7cf33 100644
--- a/tests/frontend/artifact_show.py
+++ b/tests/frontend/artifact_show.py
@@ -28,6 +28,7 @@ from tests.testutils import create_artifact_share
# Project directory
DATA_DIR = os.path.join(os.path.dirname(os.path.realpath(__file__)), "project",)
+SIMPLE_DIR = os.path.join(os.path.dirname(os.path.realpath(__file__)), "simple",)
# Test artifact show
@@ -102,6 +103,72 @@ def test_artifact_show_artifact_ref(cli, tmpdir, datafiles):
assert "cached {}".format(artifact_ref) in result.output
+# Test artifact show glob behaviors
+@pytest.mark.datafiles(SIMPLE_DIR)
+@pytest.mark.parametrize(
+ "pattern,expected_prefixes",
+ [
+ # List only artifact results in the test/project
+ #
+ ("test/**", ["test/target/", "test/target/", "test/compose-all/", "test/import-bin", "test/import-dev"]),
+ # List only artifact results by their .bst element names
+ #
+ ("**.bst", ["import-bin.bst", "import-dev.bst", "compose-all.bst", "target.bst", "subdir/target.bst"]),
+ # List only the import artifact results
+ #
+ ("import*.bst", ["import-bin.bst", "import-dev.bst"]),
+ ],
+ ids=["test/**", "**.bst", "import*.bst"],
+)
+def test_artifact_show_glob(cli, tmpdir, datafiles, pattern, expected_prefixes):
+ project = str(datafiles)
+
+ result = cli.run(project=project, args=["build", "target.bst"])
+ result.assert_success()
+
+ result = cli.run(project=project, args=["artifact", "show", pattern])
+ result.assert_success()
+
+ output = result.output.strip().splitlines()
+
+ # Assert that the number of results match the number of expected results
+ assert len(output) == len(expected_prefixes)
+
+ # Assert that each expected result was found.
+ for expected_prefix in expected_prefixes:
+ found = False
+ for result_line in output:
+ result_split = result_line.split()
+ if result_split[-1].startswith(expected_prefix):
+ found = True
+ break
+ assert found, "Expected result {} not found".format(expected_prefix)
+
+
+# Test artifact show glob behaviors
+@pytest.mark.datafiles(SIMPLE_DIR)
+@pytest.mark.parametrize(
+ "pattern",
+ [
+ # Catch all glob will match everything, that is an error since the glob matches
+ # both elements and artifacts
+ #
+ "**",
+ # This glob is more selective but will also match both artifacts and elements
+ #
+ "**import-bin**",
+ ],
+)
+def test_artifact_show_doubly_matched_glob_error(cli, tmpdir, datafiles, pattern):
+ project = str(datafiles)
+
+ result = cli.run(project=project, args=["build", "target.bst"])
+ result.assert_success()
+
+ result = cli.run(project=project, args=["artifact", "show", pattern])
+ result.assert_main_error(ErrorDomain.STREAM, "glob-elements-and-artifacts")
+
+
# Test artifact show artifact in remote
@pytest.mark.datafiles(DATA_DIR)
def test_artifact_show_element_available_remotely(cli, tmpdir, datafiles):