1 /** 2 Copyright: Copyright (c) 2019, Joakim Brännström. All rights reserved. 3 License: $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost Software License 1.0) 4 Author: Joakim Brännström (joakim.brannstrom@gmx.com) 5 */ 6 module integration; 7 8 import core.thread : Thread; 9 import core.time : dur; 10 11 import config; 12 13 @("shall setup a test environment") 14 unittest { 15 makeTestArea; 16 } 17 18 @("shall snapshot local data to dest when executed backup") 19 unittest { 20 auto ta = makeTestArea; 21 ta.writeConfigFromTemplate(inTestData("test_local.toml"), ta.sandboxPath); 22 ta.writeDummyData("some data"); 23 24 ta.execDs("backup").status.shouldEqual(0); 25 26 const found = ta.findFile("dst", "file.txt"); 27 found.length.shouldEqual(1); 28 found[0].dirName.dirName.baseName.shouldEqual("dst"); 29 readText(found[0]).shouldEqual("some data"); 30 } 31 32 @("shall snapshot remote to local dest when executed backup") 33 unittest { 34 auto ta = makeTestArea; 35 ta.writeConfigFromTemplate(inTestData("test_remote_to_local.toml"), ta.sandboxPath); 36 ta.writeDummyData("some data"); 37 38 ta.execDs("backup").status.shouldEqual(0); 39 40 const found = ta.findFile("dst", "file.txt"); 41 found.length.shouldEqual(1); 42 found[0].dirName.dirName.baseName.shouldEqual("dst"); 43 readText(found[0]).shouldEqual("some data"); 44 } 45 46 @("shall snapshot local to remote dest when executed backup") 47 unittest { 48 auto ta = makeTestArea; 49 ta.writeConfigFromTemplate(inTestData("test_local_to_remote.toml"), 50 dsnapshotPath, ta.sandboxPath); 51 ta.writeDummyData("some data"); 52 53 ta.execDs("backup").status.shouldEqual(0); 54 55 const found = ta.findFile("dst", "file.txt"); 56 found.length.shouldEqual(1); 57 found[0].dirName.dirName.baseName.shouldEqual("dst"); 58 readText(found[0]).shouldEqual("some data"); 59 } 60 61 @("shall keep nr+1 snapshots from a multi-span configuration when executing backup") 62 unittest { 63 auto ta = makeTestArea; 64 ta.writeConfigFromTemplate(inTestData("test_multiple_spans.toml"), ta.sandboxPath); 65 ta.writeDummyData("some data"); 66 67 foreach (a; 0 .. 16) { 68 Thread.sleep(20.dur!"msecs"); 69 ta.execDs("backup").status.shouldEqual(0); 70 } 71 72 const found = ta.findFile("dst", "file.txt"); 73 found.length.shouldEqual(14); 74 foreach (f; found) { 75 f.dirName.dirName.baseName.shouldEqual("dst"); 76 readText(f).shouldEqual("some data"); 77 } 78 } 79 80 @("shall calculate the disk usage of a local destination when executing diskusage") 81 unittest { 82 auto ta = makeTestArea; 83 ta.writeConfigFromTemplate(inTestData("test_local.toml"), ta.sandboxPath); 84 ta.writeDummyData("0123456789"); 85 86 ta.execDs("backup").status.shouldEqual(0); 87 auto res = ta.execDs("diskusage", "-s", "a"); 88 89 res.status.shouldEqual(0); 90 ta.sandboxPath.shouldBeIn(res.output); 91 "total".shouldBeIn(res.output); 92 } 93 94 @("shall calculate the disk usage of a remote destination when executing diskusage") 95 unittest { 96 auto ta = makeTestArea; 97 ta.writeConfigFromTemplate(inTestData("test_local_to_remote.toml"), 98 dsnapshotPath, ta.sandboxPath); 99 ta.writeDummyData("0123456789"); 100 101 ta.execDs("backup").status.shouldEqual(0); 102 auto res = ta.execDs("diskusage", "-s", "a"); 103 104 res.status.shouldEqual(0); 105 ta.sandboxPath.shouldBeIn(res.output); 106 "total".shouldBeIn(res.output); 107 } 108 109 @("shall verify the configuration when executing verifyconfig") 110 unittest { 111 auto ta = makeTestArea; 112 ta.writeConfigFromTemplate(inTestData("test_local_to_remote.toml"), 113 dsnapshotPath, ta.sandboxPath); 114 115 auto res = ta.execDs("verifyconfig"); 116 117 res.status.shouldEqual(0); 118 "Done".shouldBeIn(res.output); 119 } 120 121 @("shall restore the latest local snapshot to destination when executing restore") 122 unittest { 123 auto ta = makeTestArea; 124 ta.writeConfigFromTemplate(inTestData("test_local.toml"), ta.sandboxPath); 125 126 ta.writeDummyData("0123456789"); 127 ta.execDs("backup").status.shouldEqual(0); 128 Thread.sleep(10.dur!"msecs"); 129 ta.writeDummyData("9876543210"); 130 ta.execDs("backup").status.shouldEqual(0); 131 ta.execDs("restore", "-s", "a", "--dst", ta.inSandboxPath("restore")).status.shouldEqual(0); 132 133 const found = ta.findFile("restore", "file.txt"); 134 found.length.shouldEqual(1); 135 // the one closest to the configured snapshot time is "best". The time is 136 // now-5min so the first snapshot should be restored. 137 readText(found[0]).shouldEqual("0123456789"); 138 } 139 140 @("shall restore the latest remote snapshot to destination when executing restore") 141 unittest { 142 auto ta = makeTestArea; 143 ta.writeConfigFromTemplate(inTestData("test_local_to_remote.toml"), 144 dsnapshotPath, ta.sandboxPath); 145 146 ta.writeDummyData("0123456789"); 147 ta.execDs("backup").status.shouldEqual(0); 148 Thread.sleep(10.dur!"msecs"); 149 ta.writeDummyData("9876543210"); 150 ta.execDs("backup").status.shouldEqual(0); 151 ta.execDs("restore", "-s", "a", "--dst", ta.inSandboxPath("restore")).status.shouldEqual(0); 152 153 const found = ta.findFile("restore", "file.txt"); 154 found.length.shouldEqual(1); 155 // the one closest to the configured snapshot time is "best". The time is 156 // now-5min so the first snapshot should be restored. 157 readText(found[0]).shouldEqual("0123456789"); 158 }