diff options
author | Dirk Hohndel <dirk@hohndel.org> | 2015-08-24 14:00:42 -0700 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2015-08-25 10:44:15 -0700 |
commit | 9f5a944107b7a8852adccd6da71dc94baa374bb5 (patch) | |
tree | b4f487b742b13261e58e98994d627d9182fa84ad /tests | |
parent | 449ba2876fd8d41262b440270e804a2f5acfbc12 (diff) | |
download | subsurface-9f5a944107b7a8852adccd6da71dc94baa374bb5.tar.gz |
Cloud storage: first test case for a very simple merge
- We add a dive while offline.
- On a different computer (here simulated by a different local cache) we
add a different file.
- Now we go back to the previous local cache (the one where we added a
different dive in the first step) and take that online (i.e., connect to
cloud storage). Now both of the new dives should have been added to our
data file.
This is a rather trivial test with no conflict and a straight forward
merge. We need to add a lot more test cases to make sure this works as
expected and doesn't leave the user with a corrupt state.
Ideally whatever happens, the user should never see an error...
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/testgitstorage.cpp | 47 | ||||
-rw-r--r-- | tests/testgitstorage.h | 1 |
2 files changed, 48 insertions, 0 deletions
diff --git a/tests/testgitstorage.cpp b/tests/testgitstorage.cpp index 5bc7924af..c262e27be 100644 --- a/tests/testgitstorage.cpp +++ b/tests/testgitstorage.cpp @@ -149,4 +149,51 @@ void TestGitStorage::testGitStorageCloudOfflineSync() clear_dive_file_data(); } +void TestGitStorage::testGitStorageCloudMerge() +{ + // now we need to mess with the local git repo to get an actual merge + // first we add another dive to the "moved away" repository, pretending we did + // another offline change there + QString cloudTestRepo("https://cloud.subsurface-divelog.org/git/ssrftest@hohndel.org[ssrftest@hohndel.org]"); + QString localCacheDir(get_local_dir("https://cloud.subsurface-divelog.org/git/ssrftest@hohndel.org", "ssrftest@hohndel.org")); + QString localCacheRepoSave = localCacheDir + "save[ssrftest@hohndel.org]"; + QCOMPARE(parse_file(qPrintable(localCacheRepoSave)), 0); + QCOMPARE(parse_file(SUBSURFACE_SOURCE "/dives/test11.xml"), 0); + process_dives(false, false); + QCOMPARE(save_dives(qPrintable(localCacheRepoSave)), 0); + clear_dive_file_data(); + + // now we open the cloud storage repo and add a different dive to it + QCOMPARE(parse_file(qPrintable(cloudTestRepo)), 0); + QCOMPARE(parse_file(SUBSURFACE_SOURCE "/dives/test12.xml"), 0); + process_dives(false, false); + QCOMPARE(save_dives(qPrintable(cloudTestRepo)), 0); + clear_dive_file_data(); + + // now we move the saved local cache into place and try to open the cloud repo + // -> this forces a merge + QDir localCacheDirectory(localCacheDir); + QCOMPARE(localCacheDirectory.removeRecursively(), true); + QDir localCacheDirectorySave(localCacheDir + "save"); + QCOMPARE(localCacheDirectory.rename(localCacheDir + "save", localCacheDir), true); + QCOMPARE(parse_file(qPrintable(cloudTestRepo)), 0); + QCOMPARE(save_dives("./SapleDivesV3plus10-11-12-merged.ssrf"), 0); + clear_dive_file_data(); + QCOMPARE(parse_file("./SampleDivesV3plus10local.ssrf"), 0); + QCOMPARE(parse_file(SUBSURFACE_SOURCE "/dives/test11.xml"), 0); + process_dives(false, false); + QCOMPARE(parse_file(SUBSURFACE_SOURCE "/dives/test12.xml"), 0); + process_dives(false, false); + QCOMPARE(save_dives("./SapleDivesV3plus10-11-12.ssrf"), 0); + QFile org("./SapleDivesV3plus10-11-12-merged.ssrf"); + org.open(QFile::ReadOnly); + QFile out("./SapleDivesV3plus10-11-12.ssrf"); + out.open(QFile::ReadOnly); + QTextStream orgS(&org); + QTextStream outS(&out); + QString readin = orgS.readAll(); + QString written = outS.readAll(); + QCOMPARE(readin, written); +} + QTEST_MAIN(TestGitStorage) diff --git a/tests/testgitstorage.h b/tests/testgitstorage.h index 43c33c228..93cf70177 100644 --- a/tests/testgitstorage.h +++ b/tests/testgitstorage.h @@ -10,6 +10,7 @@ private slots: void testGitStorageLocal(); void testGitStorageCloud(); void testGitStorageCloudOfflineSync(); + void testGitStorageCloudMerge(); }; #endif // TESTGITSTORAGE_H |