Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/duplicati/duplicati.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDean Ferreyra <dean@octw.com>2020-09-13 02:59:41 +0300
committerDean Ferreyra <dean@octw.com>2020-09-13 03:03:48 +0300
commite3b8a12ec11aa19e61b722f37b4bcad97bbec41f (patch)
treeeb3b1c3496c68112fbe2d945dae61774fe6228fa /Duplicati/UnitTest
parenteafe7320e90996633889ea1c64d3fd94deb81691 (diff)
Unit test improvements per review comments
Diffstat (limited to 'Duplicati/UnitTest')
-rw-r--r--Duplicati/UnitTest/ProblematicPathTests.cs7
-rwxr-xr-xDuplicati/UnitTest/SymLinkTests.cs94
2 files changed, 38 insertions, 63 deletions
diff --git a/Duplicati/UnitTest/ProblematicPathTests.cs b/Duplicati/UnitTest/ProblematicPathTests.cs
index ac1d075f1..eb2e815d6 100644
--- a/Duplicati/UnitTest/ProblematicPathTests.cs
+++ b/Duplicati/UnitTest/ProblematicPathTests.cs
@@ -81,12 +81,7 @@ namespace Duplicati.UnitTest
Assert.AreEqual(0, restoreResults.Errors.Count());
Assert.AreEqual(0, restoreResults.Warnings.Count());
- foreach (string directory in directories)
- {
- string directoryName = SystemIO.IO_OS.PathGetFileName(directory);
- string restoredDirectory = SystemIO.IO_OS.PathCombine(this.RESTOREFOLDER, directoryName);
- TestUtils.AssertDirectoryTreesAreEquivalent(directory, restoredDirectory, true, "Restore");
- }
+ TestUtils.AssertDirectoryTreesAreEquivalent(this.DATAFOLDER, this.RESTOREFOLDER, true, "Restore");
// List results using * should return a match for each directory.
IListResults listResults = c.List(SystemIO.IO_OS.PathCombine(dirWithAsterisk, file));
diff --git a/Duplicati/UnitTest/SymLinkTests.cs b/Duplicati/UnitTest/SymLinkTests.cs
index 4b52bb384..b2a178f09 100755
--- a/Duplicati/UnitTest/SymLinkTests.cs
+++ b/Duplicati/UnitTest/SymLinkTests.cs
@@ -14,7 +14,10 @@ namespace Duplicati.UnitTest
{
[Test]
[Category("SymLink")]
- public void SymLinkPolicy()
+ [TestCase(Options.SymlinkStrategy.Store)]
+ [TestCase(Options.SymlinkStrategy.Follow)]
+ [TestCase(Options.SymlinkStrategy.Ignore)]
+ public void SymLinkPolicy(Options.SymlinkStrategy symlinkPolicy)
{
// Create symlink target directory
const string targetDirName = "target";
@@ -41,65 +44,42 @@ namespace Duplicati.UnitTest
Assert.Ignore($"Client could not create a symbolic link. Error reported: {e.Message}");
}
- // Perform backups using all symlink policies and verify restores
- var symlinkPolicies = new[] { Options.SymlinkStrategy.Store, Options.SymlinkStrategy.Follow, Options.SymlinkStrategy.Ignore };
+ // Backup all files with given symlink policy
Dictionary<string, string> restoreOptions = new Dictionary<string, string>(this.TestOptions) { ["restore-path"] = this.RESTOREFOLDER };
- foreach (var symlinkPolicy in symlinkPolicies)
+ Dictionary<string, string> backupOptions = new Dictionary<string, string>(this.TestOptions) { ["symlink-policy"] = symlinkPolicy.ToString() };
+ using (Controller c = new Controller("file://" + this.TARGETFOLDER, backupOptions, null))
{
- // Backup all files with given symlink policy
- Dictionary<string, string> backupOptions = new Dictionary<string, string>(this.TestOptions) { ["symlink-policy"] = symlinkPolicy.ToString() };
- using (Controller c = new Controller("file://" + this.TARGETFOLDER, backupOptions, null))
- {
- IBackupResults backupResults = c.Backup(new[] { this.DATAFOLDER });
- Assert.AreEqual(0, backupResults.Errors.Count());
- Assert.AreEqual(0, backupResults.Warnings.Count());
- }
- // Restore all files
- using (Controller c = new Controller("file://" + this.TARGETFOLDER, restoreOptions, null))
- {
- IRestoreResults restoreResults = c.Restore(null);
- Assert.AreEqual(0, restoreResults.Errors.Count());
- Assert.AreEqual(0, restoreResults.Warnings.Count());
+ IBackupResults backupResults = c.Backup(new[] { this.DATAFOLDER });
+ Assert.AreEqual(0, backupResults.Errors.Count());
+ Assert.AreEqual(0, backupResults.Warnings.Count());
+ }
+ // Restore all files
+ using (Controller c = new Controller("file://" + this.TARGETFOLDER, restoreOptions, null))
+ {
+ IRestoreResults restoreResults = c.Restore(null);
+ Assert.AreEqual(0, restoreResults.Errors.Count());
+ Assert.AreEqual(0, restoreResults.Warnings.Count());
- // Verify that symlink policy was followed
- var restoreSymlinkDir = systemIO.PathCombine(this.RESTOREFOLDER, symlinkDirName);
- switch (symlinkPolicy)
- {
- case Options.SymlinkStrategy.Store:
- // Restore should contain an actual symlink to the original target
- Assert.That(systemIO.IsSymlink(restoreSymlinkDir), Is.True);
- var restoredSymlinkFullPath = systemIO.PathGetFullPath(systemIO.GetSymlinkTarget(restoreSymlinkDir));
- var symlinkTargetFullPath = systemIO.PathGetFullPath(targetDir);
- Assert.That(restoredSymlinkFullPath, Is.EqualTo(symlinkTargetFullPath));
- break;
- case Options.SymlinkStrategy.Follow:
- // Restore should contain a regular directory with copies of the files in the symlink target
- Assert.That(systemIO.IsSymlink(restoreSymlinkDir), Is.False);
- TestUtils.AssertDirectoryTreesAreEquivalent(targetDir, restoreSymlinkDir, true, $"Symlink policy: {Options.SymlinkStrategy.Store}");
- break;
- case Options.SymlinkStrategy.Ignore:
- // Restore should not contain the symlink at all
- Assert.That(systemIO.DirectoryExists(restoreSymlinkDir), Is.False);
- break;
- }
- // Prepare for a fresh backup and restore cycle
- foreach (var dir in systemIO.EnumerateDirectories(this.RESTOREFOLDER))
- {
- systemIO.DirectoryDelete(dir, true);
- }
- foreach (var file in systemIO.EnumerateFiles(this.RESTOREFOLDER))
- {
- systemIO.FileDelete(file);
- }
- c.DeleteAllRemoteFiles();
- if (systemIO.FileExists(this.DBFILE))
- {
- systemIO.FileDelete(this.DBFILE);
- }
- if (systemIO.FileExists($"{this.DBFILE}-journal"))
- {
- systemIO.FileDelete($"{this.DBFILE}-journal");
- }
+ // Verify that symlink policy was followed
+ var restoreSymlinkDir = systemIO.PathCombine(this.RESTOREFOLDER, symlinkDirName);
+ switch (symlinkPolicy)
+ {
+ case Options.SymlinkStrategy.Store:
+ // Restore should contain an actual symlink to the original target
+ Assert.That(systemIO.IsSymlink(restoreSymlinkDir), Is.True);
+ var restoredSymlinkFullPath = systemIO.PathGetFullPath(systemIO.GetSymlinkTarget(restoreSymlinkDir));
+ var symlinkTargetFullPath = systemIO.PathGetFullPath(targetDir);
+ Assert.That(restoredSymlinkFullPath, Is.EqualTo(symlinkTargetFullPath));
+ break;
+ case Options.SymlinkStrategy.Follow:
+ // Restore should contain a regular directory with copies of the files in the symlink target
+ Assert.That(systemIO.IsSymlink(restoreSymlinkDir), Is.False);
+ TestUtils.AssertDirectoryTreesAreEquivalent(targetDir, restoreSymlinkDir, true, $"Symlink policy: {Options.SymlinkStrategy.Store}");
+ break;
+ case Options.SymlinkStrategy.Ignore:
+ // Restore should not contain the symlink at all
+ Assert.That(systemIO.DirectoryExists(restoreSymlinkDir), Is.False);
+ break;
}
}
}