summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJames Ennis <james.ennis@codethink.co.uk>2019-03-27 17:22:33 +0000
committerJames Ennis <james.ennis@codethink.co.uk>2019-03-28 12:47:47 +0000
commit69024535dd2ff2c95555f9ed47089ebe12345878 (patch)
tree85c23bb35a1f6c8d7488f17f455f5602f656c64d
parentbef450dd6f31a8ff5e9084b71983a34676abce15 (diff)
downloadbuildstream-jennis/track_is_overworking.tar.gz
tests: Add a track test to ensure that we do not needlessly overwrite filesjennis/track_is_overworking
-rw-r--r--tests/frontend/track.py40
1 files changed, 40 insertions, 0 deletions
diff --git a/tests/frontend/track.py b/tests/frontend/track.py
index 13d1d4646..46f5bcf67 100644
--- a/tests/frontend/track.py
+++ b/tests/frontend/track.py
@@ -355,3 +355,43 @@ def test_track_error_cannot_write_file(cli, tmpdir, datafiles):
result.assert_task_error(ErrorDomain.SOURCE, 'save-ref-error')
finally:
os.chmod(element_path, stat.S_IMODE(st.st_mode))
+
+
+@pytest.mark.datafiles(DATA_DIR)
+def test_no_needless_overwrite(cli, tmpdir, datafiles):
+ project = os.path.join(datafiles.dirname, datafiles.basename)
+ dev_files_path = os.path.join(project, 'files', 'dev-files')
+ element_path = os.path.join(project, 'elements')
+ target = 'track-test-target.bst'
+
+ # Create our repo object of the given source type with
+ # the dev files, and then collect the initial ref.
+ #
+ repo = create_repo('git', str(tmpdir))
+ repo.create(dev_files_path)
+
+ # Write out our test target and assert it exists
+ generate_element(repo, os.path.join(element_path, target))
+ path_to_target = os.path.join(element_path, target)
+ assert os.path.exists(path_to_target)
+ creation_mtime = os.path.getmtime(path_to_target)
+
+ # Assert tracking is needed
+ states = cli.get_element_states(project, [target])
+ assert states[target] == 'no reference'
+
+ # Perform the track
+ result = cli.run(project=project, args=['source', 'track', target])
+ result.assert_success()
+
+ track1_mtime = os.path.getmtime(path_to_target)
+
+ assert creation_mtime != track1_mtime
+
+ # Now (needlessly) track again
+ result = cli.run(project=project, args=['source', 'track', target])
+ result.assert_success()
+
+ track2_mtime = os.path.getmtime(path_to_target)
+
+ assert track1_mtime == track2_mtime