From 7e1067e99681c5c5c8d6809656d0e9ab66cbc49c Mon Sep 17 00:00:00 2001 From: Kenneth Skovhede Date: Tue, 23 Feb 2016 20:57:18 +0100 Subject: [PATCH] Added extra test for the simple a + b test --- Duplicati/UnitTest/Issue1410.cs | 82 +++++++++++++++++++++++++++++++-- 1 file changed, 79 insertions(+), 3 deletions(-) diff --git a/Duplicati/UnitTest/Issue1410.cs b/Duplicati/UnitTest/Issue1410.cs index 7cc7d6ef5..13f8f38ee 100644 --- a/Duplicati/UnitTest/Issue1410.cs +++ b/Duplicati/UnitTest/Issue1410.cs @@ -14,12 +14,88 @@ // You should have received a copy of the GNU Lesser General Public // License along with this library; if not, write to the Free Software // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -using System; using System.IO; using NUnit.Framework; using System.Linq; using System.Collections.Generic; +using System; +using System.IO; +using NUnit.Framework; +using System.Linq; +using System.Collections.Generic; namespace Duplicati.UnitTest { - [TestFixture] public class Issue1410 : BasicSetupHelper - { [TestFixtureSetUp()] public override void PrepareSourceData() { base.PrepareSourceData(); Directory.CreateDirectory(DATAFOLDER); Directory.CreateDirectory(TARGETFOLDER); } [Test] public void RunCommands() { var data = new byte[1024 * 1024 * 10]; //File.WriteAllText(Path.Combine(DATAFOLDER, "a"), "hi"); File.WriteAllBytes(Path.Combine(DATAFOLDER, "a"), data); using(var c = new Library.Main.Controller("file://" + TARGETFOLDER, TestOptions, null)) c.Backup(new string[] { DATAFOLDER }); new Random().NextBytes(data); //File.WriteAllText(Path.Combine(DATAFOLDER, "b"), "there"); File.WriteAllBytes(Path.Combine(DATAFOLDER, "b"), data); using(var c = new Library.Main.Controller("file://" + TARGETFOLDER, TestOptions, null)) c.Backup(new string[] { DATAFOLDER }); using(var c = new Library.Main.Controller("file://" + TARGETFOLDER, TestOptions.Expand(new { version = 0 }), null)) { var r = c.List("*"); Console.WriteLine("Newest before deleting:"); Console.WriteLine(string.Join(Environment.NewLine, r.Files.Select(x => x.Path))); Assert.AreEqual(3, r.Files.Count()); } using(var c = new Library.Main.Controller("file://" + TARGETFOLDER, TestOptions.Expand(new { version = 0, no_local_db = true }), null)) { var r = c.List("*"); Console.WriteLine("Newest without db:"); Console.WriteLine(string.Join(Environment.NewLine, r.Files.Select(x => x.Path))); Assert.AreEqual(3, r.Files.Count()); } File.Delete(DBFILE); using(var c = new Library.Main.Controller("file://" + TARGETFOLDER, TestOptions, null)) c.Repair(); using(var c = new Library.Main.Controller("file://" + TARGETFOLDER, TestOptions, null)) Assert.AreEqual(c.List().Filesets.Count(), 2); using(var c = new Library.Main.Controller("file://" + TARGETFOLDER, TestOptions.Expand(new { version = 1 }), null)) { var r = c.List("*"); Console.WriteLine("Oldest after delete:"); Console.WriteLine(string.Join(Environment.NewLine, r.Files.Select(x => x.Path))); Assert.AreEqual(2, r.Files.Count()); } using(var c = new Library.Main.Controller("file://" + TARGETFOLDER, TestOptions.Expand(new { version = 0 }), null)) { var r = c.List("*"); Console.WriteLine("Newest after delete:"); Console.WriteLine(string.Join(Environment.NewLine, r.Files.Select(x => x.Path))); Assert.AreEqual(3, r.Files.Count()); } } + [TestFixture] + public class Issue1410 : BasicSetupHelper + { + [TestFixtureSetUp()] + public override void PrepareSourceData() + { + base.PrepareSourceData(); + + Directory.CreateDirectory(DATAFOLDER); + Directory.CreateDirectory(TARGETFOLDER); + } + + [Test] + public void RunCommands() + { + TestOptions["verbose"] = "true"; + + var data = new byte[1024 * 1024 * 10]; + File.WriteAllBytes(Path.Combine(DATAFOLDER, "a"), data); + using(var c = new Library.Main.Controller("file://" + TARGETFOLDER, TestOptions, null)) + c.Backup(new string[] { DATAFOLDER }); + + using(var c = new Library.Main.Controller("file://" + TARGETFOLDER, TestOptions.Expand(new { version = 0 }), null)) + { + var r = c.List("*"); + Console.WriteLine("In first backup:"); + Console.WriteLine(string.Join(Environment.NewLine, r.Files.Select(x => x.Path))); + } + + new Random().NextBytes(data); + File.WriteAllBytes(Path.Combine(DATAFOLDER, "b"), data); + using(var c = new Library.Main.Controller("file://" + TARGETFOLDER, TestOptions, null)) + c.Backup(new string[] { DATAFOLDER }); + + using(var c = new Library.Main.Controller("file://" + TARGETFOLDER, TestOptions.Expand(new { version = 0 }), null)) + { + var r = c.List("*"); + Console.WriteLine("Newest before deleting:"); + Console.WriteLine(string.Join(Environment.NewLine, r.Files.Select(x => x.Path))); + Assert.AreEqual(3, r.Files.Count()); + } + + using(var c = new Library.Main.Controller("file://" + TARGETFOLDER, TestOptions.Expand(new { version = 0, no_local_db = true }), null)) + { + var r = c.List("*"); + Console.WriteLine("Newest without db:"); + Console.WriteLine(string.Join(Environment.NewLine, r.Files.Select(x => x.Path))); + Assert.AreEqual(3, r.Files.Count()); + } + + + File.Delete(DBFILE); + using(var c = new Library.Main.Controller("file://" + TARGETFOLDER, TestOptions, null)) + c.Repair(); + + using(var c = new Library.Main.Controller("file://" + TARGETFOLDER, TestOptions, null)) + Assert.AreEqual(c.List().Filesets.Count(), 2); + + using(var c = new Library.Main.Controller("file://" + TARGETFOLDER, TestOptions.Expand(new { version = 1 }), null)) + { + var r = c.List("*"); + Console.WriteLine("Oldest after delete:"); + Console.WriteLine(string.Join(Environment.NewLine, r.Files.Select(x => x.Path))); + Assert.AreEqual(2, r.Files.Count()); + } + + using(var c = new Library.Main.Controller("file://" + TARGETFOLDER, TestOptions.Expand(new { version = 0 }), null)) + { + var r = c.List("*"); + Console.WriteLine("Newest after delete:"); + Console.WriteLine(string.Join(Environment.NewLine, r.Files.Select(x => x.Path))); + Assert.AreEqual(3, r.Files.Count()); + } + } } }