Browse Source

additional test for rmdir a dir another peer created

ameba23 3 years ago
parent
commit
087a004fe2
1 changed files with 59 additions and 1 deletions
  1. 59
    1
      test/index.test.js

+ 59
- 1
test/index.test.js View File

@@ -247,7 +247,6 @@ describe('mount', (context) => {
247 247
         assert.error(err, 'no error on ls')
248 248
         assert.true(output[0].split('\n').indexOf('hello.txt') > -1, 'file successfully replicated')
249 249
         run(`unlink ${storage.blue}/hello.txt`, (err, output) => {
250
-        // fs.unlink(path.join(storage.blue, 'hello.txt'), (err) => {
251 250
           assert.error(err, 'no error on rm file')
252 251
           run(`cat ${storage.blue}/hello.txt`, (err, output) => {
253 252
             assert.ok(err, 'error on cat out file')
@@ -256,6 +255,7 @@ describe('mount', (context) => {
256 255
               assert.error(err, 'no error on replicate')
257 256
               run(`ls ${storage.orange}`, (err, output) => {
258 257
                 assert.error(err, 'no error')
258
+                //TODO this line should also use .split:
259 259
                 assert.ok(output.indexOf('hello.txt\n') < 0, 'ls does not find the file')
260 260
                 cleanup(destroy.orange, storage.orange).then(() => {
261 261
                   cleanup(destroy.blue, storage.blue).then(next)
@@ -268,6 +268,64 @@ describe('mount', (context) => {
268 268
     }
269 269
   })
270 270
 
271
+  context("replicate - rmdir another peer's dir - using unix commands", (assert, next) => {
272
+    var feedsOnDisk = {
273
+      orange: tmp(),
274
+      blue: tmp()
275
+    }
276
+    var orangeDrive = KappaDrive(feedsOnDisk.orange)
277
+    var blueDrive = KappaDrive(feedsOnDisk.blue)
278
+
279
+    var storage = {}
280
+    var destroy = {}
281
+
282
+    function setup (drive, colour, cb) {
283
+      storage[colour] = tmp()
284
+      mount(drive, storage[colour]).then((destroyFn) => {
285
+        destroy[colour] = destroyFn
286
+        drive.ready(cb)
287
+      })
288
+    }
289
+
290
+    setup(orangeDrive, 'orange', function () {
291
+      setup(blueDrive, 'blue', function () {
292
+        run(`mkdir ${storage.orange}/cabbage`, (err, output) => {
293
+          assert.error(err, 'no error on mkdir')
294
+          // 'seed' the blue drive with a file (TODO this is a hack)
295
+          run(`echo "this file is not needed" > ${storage.blue}/blue.txt`, (err, output) => {
296
+            assert.error(err, 'no error on echo to file')
297
+            replicate(orangeDrive, blueDrive, check)
298
+          })
299
+        })
300
+      })
301
+    })
302
+
303
+    function check (err) {
304
+      assert.error(err, 'no error on replicate')
305
+      run(`ls ${storage.blue}`, (err, output) => {
306
+        assert.error(err, 'no error on ls')
307
+        assert.true(output[0].split('\n').indexOf('cabbage') > -1, 'dir successfully replicated')
308
+        run(`rmdir ${storage.blue}/cabbage`, (err, output) => {
309
+          assert.error(err, 'no error on rmdir')
310
+          run(`ls ${storage.blue}`, (err, output) => {
311
+            assert.error(err, 'error on ls')
312
+            assert.false(output[0].split('\n').indexOf('cabbage') > -1, 'ls no longer lists dir')
313
+            replicate(orangeDrive, blueDrive, (err) => {
314
+              assert.error(err, 'no error on replicate')
315
+              run(`ls ${storage.orange}`, (err, output) => {
316
+                assert.error(err, 'no error')
317
+                assert.false(output[0].split('\n').indexOf('cabbage') > -1, 'ls no longer lists dir')
318
+                cleanup(destroy.orange, storage.orange).then(() => {
319
+                  cleanup(destroy.blue, storage.blue).then(next)
320
+                })
321
+              })
322
+            })
323
+          })
324
+        })
325
+      })
326
+    }
327
+  })
328
+
271 329
   context("replicate - append to another peer's empty file - using unix commands", (assert, next) => {
272 330
     var feedsOnDisk = {
273 331
       orange: tmp(),