summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTristan Van Berkom <tristan.vanberkom@codethink.co.uk>2018-04-09 15:17:46 +0900
committerTristan Van Berkom <tristan.vanberkom@codethink.co.uk>2018-04-09 20:24:34 +0900
commitb8b417248420ce40db8550073d316cee02c5fbdb (patch)
tree32aec5eefcbc37c5312c8702709b309751466f72
parent9e74988e0c5b22d5073c1436ca1648d28f2cac26 (diff)
downloadbuildstream-352-race-condition-incorrect-saving-of-running-files-in-workspaces-yml-local-state-file.tar.gz
This was previously only working for added or removed files and broken for modified files.
-rw-r--r--tests/frontend/workspace.py77
1 files changed, 77 insertions, 0 deletions
diff --git a/tests/frontend/workspace.py b/tests/frontend/workspace.py
index b921ca1a0..57b6fe2ba 100644
--- a/tests/frontend/workspace.py
+++ b/tests/frontend/workspace.py
@@ -281,6 +281,83 @@ def test_build(cli, tmpdir, datafiles, kind, strict):
assert not os.path.exists(os.path.join(checkout, 'usr', 'bin', 'hello'))
+@pytest.mark.datafiles(DATA_DIR)
+@pytest.mark.parametrize("modification", [("addfile"), ("removefile"), ("modifyfile")])
+@pytest.mark.parametrize("strict", [("strict"), ("non-strict")])
+def test_detect_modifications(cli, tmpdir, datafiles, modification, strict):
+ element_name, project, workspace = open_workspace(cli, tmpdir, datafiles, 'git', False)
+ checkout = os.path.join(str(tmpdir), 'checkout')
+
+ # Configure strict mode
+ strict_mode = True
+ if strict != 'strict':
+ strict_mode = False
+ cli.configure({
+ 'projects': {
+ 'test': {
+ 'strict': strict_mode
+ }
+ }
+ })
+
+ # Build clean workspace
+ assert cli.get_element_state(project, element_name) == 'buildable'
+ assert cli.get_element_key(project, element_name) == "{:?<64}".format('')
+ result = cli.run(project=project, args=['build', element_name])
+ result.assert_success()
+ assert cli.get_element_state(project, element_name) == 'cached'
+ assert cli.get_element_key(project, element_name) != "{:?<64}".format('')
+
+ # Modify the workspace in various different ways, ensuring we
+ # properly detect the changes.
+ #
+ if modification == 'addfile':
+ os.makedirs(os.path.join(workspace, 'etc'))
+ with open(os.path.join(workspace, 'etc', 'pony.conf'), 'w') as f:
+ f.write("PONY='pink'")
+ elif modification == 'removefile':
+ os.remove(os.path.join(workspace, 'usr', 'bin', 'hello'))
+ elif modification == 'modifyfile':
+ with open(os.path.join(workspace, 'usr', 'bin', 'hello'), 'w') as f:
+ f.write('cookie')
+ else:
+ # This cannot be reached
+ assert 0
+
+ # First assert that the state is properly detected
+ assert cli.get_element_state(project, element_name) == 'buildable'
+ assert cli.get_element_key(project, element_name) == "{:?<64}".format('')
+
+ # Since there are different things going on at `bst build` time
+ # than `bst show` time, we also want to build / checkout again,
+ # and ensure that the result contains what we expect.
+ result = cli.run(project=project, args=['build', element_name])
+ result.assert_success()
+ assert cli.get_element_state(project, element_name) == 'cached'
+ assert cli.get_element_key(project, element_name) != "{:?<64}".format('')
+
+ # Checkout the result
+ result = cli.run(project=project, args=[
+ 'checkout', element_name, checkout
+ ])
+ result.assert_success()
+
+ # Check the result for the changes we made
+ #
+ if modification == 'addfile':
+ filename = os.path.join(checkout, 'etc', 'pony.conf')
+ assert os.path.exists(filename)
+ elif modification == 'removefile':
+ assert not os.path.exists(os.path.join(checkout, 'usr', 'bin', 'hello'))
+ elif modification == 'modifyfile':
+ with open(os.path.join(workspace, 'usr', 'bin', 'hello'), 'r') as f:
+ data = f.read()
+ assert data == 'cookie'
+ else:
+ # This cannot be reached
+ assert 0
+
+
# Ensure that various versions that should not be accepted raise a
# LoadError.INVALID_DATA
@pytest.mark.datafiles(DATA_DIR)