tests: Add workspace tests for filters
diff --git a/tests/plugins/filter.py b/tests/plugins/filter.py
index a8e7257..f38bc43 100644
--- a/tests/plugins/filter.py
+++ b/tests/plugins/filter.py
@@ -1,5 +1,6 @@
 import os
 import pytest
+import shutil
 from tests.testutils.runcli import cli
 from buildstream._exceptions import ErrorDomain
 
@@ -85,3 +86,72 @@
     project = os.path.join(datafiles.dirname, datafiles.basename)
     result = cli.run(project=project, args=['build', 'forbidden-also-rdep.bst'])
     result.assert_main_error(ErrorDomain.PIPELINE, 'filter-bdepend-also-rdepend')
+
+
+@pytest.mark.datafiles(os.path.join(DATA_DIR, 'basic'))
+def test_filter_workspace_open(datafiles, cli, tmpdir):
+    project = os.path.join(datafiles.dirname, datafiles.basename)
+    workspace_dir = os.path.join(tmpdir.dirname, tmpdir.basename, "workspace")
+    result = cli.run(project=project, args=['workspace', 'open', 'deps-permitted.bst', workspace_dir])
+    result.assert_success()
+    assert os.path.exists(os.path.join(workspace_dir, "foo"))
+    assert os.path.exists(os.path.join(workspace_dir, "bar"))
+    assert os.path.exists(os.path.join(workspace_dir, "baz"))
+
+
+@pytest.mark.datafiles(os.path.join(DATA_DIR, 'basic'))
+def test_filter_workspace_build(datafiles, cli, tmpdir):
+    project = os.path.join(datafiles.dirname, datafiles.basename)
+    tempdir = os.path.join(tmpdir.dirname, tmpdir.basename)
+    workspace_dir = os.path.join(tempdir, "workspace")
+    result = cli.run(project=project, args=['workspace', 'open', 'output-orphans.bst', workspace_dir])
+    result.assert_success()
+    src = os.path.join(workspace_dir, "foo")
+    dst = os.path.join(workspace_dir, "quux")
+    shutil.copyfile(src, dst)
+    result = cli.run(project=project, args=['build', 'output-orphans.bst'])
+    result.assert_success()
+    checkout_dir = os.path.join(tempdir, "checkout")
+    result = cli.run(project=project, args=['checkout', 'output-orphans.bst', checkout_dir])
+    result.assert_success()
+    assert os.path.exists(os.path.join(checkout_dir, "quux"))
+
+
+@pytest.mark.datafiles(os.path.join(DATA_DIR, 'basic'))
+def test_filter_workspace_close(datafiles, cli, tmpdir):
+    project = os.path.join(datafiles.dirname, datafiles.basename)
+    tempdir = os.path.join(tmpdir.dirname, tmpdir.basename)
+    workspace_dir = os.path.join(tempdir, "workspace")
+    result = cli.run(project=project, args=['workspace', 'open', 'output-orphans.bst', workspace_dir])
+    result.assert_success()
+    src = os.path.join(workspace_dir, "foo")
+    dst = os.path.join(workspace_dir, "quux")
+    shutil.copyfile(src, dst)
+    result = cli.run(project=project, args=['workspace', 'close', 'deps-permitted.bst'])
+    result.assert_success()
+    result = cli.run(project=project, args=['build', 'output-orphans.bst'])
+    result.assert_success()
+    checkout_dir = os.path.join(tempdir, "checkout")
+    result = cli.run(project=project, args=['checkout', 'output-orphans.bst', checkout_dir])
+    result.assert_success()
+    assert not os.path.exists(os.path.join(checkout_dir, "quux"))
+
+
+@pytest.mark.datafiles(os.path.join(DATA_DIR, 'basic'))
+def test_filter_workspace_reset(datafiles, cli, tmpdir):
+    project = os.path.join(datafiles.dirname, datafiles.basename)
+    tempdir = os.path.join(tmpdir.dirname, tmpdir.basename)
+    workspace_dir = os.path.join(tempdir, "workspace")
+    result = cli.run(project=project, args=['workspace', 'open', 'output-orphans.bst', workspace_dir])
+    result.assert_success()
+    src = os.path.join(workspace_dir, "foo")
+    dst = os.path.join(workspace_dir, "quux")
+    shutil.copyfile(src, dst)
+    result = cli.run(project=project, args=['workspace', 'reset', 'deps-permitted.bst'])
+    result.assert_success()
+    result = cli.run(project=project, args=['build', 'output-orphans.bst'])
+    result.assert_success()
+    checkout_dir = os.path.join(tempdir, "checkout")
+    result = cli.run(project=project, args=['checkout', 'output-orphans.bst', checkout_dir])
+    result.assert_success()
+    assert not os.path.exists(os.path.join(checkout_dir, "quux"))