Browse Source

Merge branch 'master' of http://ledger-git.dyne.org:3000/CoBox/kappa-drive-mount

* 'master' of http://ledger-git.dyne.org:3000/CoBox/kappa-drive-mount:
  move helper scripts to other repo
ameba23 3 years ago
parent
commit
6756deea03
2 changed files with 0 additions and 212 deletions
  1. 0
    180
      test/mount-extratests.js
  2. 0
    32
      test/mount_hyperdrive.js

+ 0
- 180
test/mount-extratests.js View File

@@ -1,180 +0,0 @@
1
-// TODO: these are a mess but just didn't want to delete them,
2
-// we might use some of this at some point
3
-
4
-
5
-  context("replicate - overwrite another peer's changes", (assert, next) => {
6
-    var feedsOnDisk = {
7
-      orange: tmp(),
8
-      blue: tmp()
9
-    }
10
-    var orangeDrive = KappaDrive(feedsOnDisk.orange)
11
-    var blueDrive = KappaDrive(feedsOnDisk.blue)
12
-
13
-    var storage = {}
14
-    var destroy = {}
15
-
16
-    function setup (drive, colour, cb) {
17
-      storage[colour] = tmp()
18
-      mount(drive, storage[colour]).then((destroyFn) => {
19
-        destroy[colour] = destroyFn
20
-        drive.ready(() => {
21
-          cb()
22
-        })
23
-      })
24
-    }
25
-
26
-    setup(orangeDrive, 'orange', function () {
27
-      setup(blueDrive, 'blue', function () {
28
-        fs.writeFile(path.join(storage.orange, 'orange.txt'), 'i like orange', (err) => {
29
-          assert.error(err, 'no error')
30
-          // 'seed' the blue drive with a file (TODO this is a hack)
31
-          fs.writeFile(path.join(storage.blue, 'blue.txt'), 'this file is not needed', (err) => {
32
-            assert.error(err, 'no error')
33
-            replicate(orangeDrive, blueDrive, check)
34
-          })
35
-        })
36
-      })
37
-    })
38
-    function check (err) {
39
-      assert.error(err, 'no error')
40
-      fs.open(path.join(storage.blue, 'orange.txt'), 'r+', (err, fd) => {
41
-        assert.error(err, 'no error')
42
-        assert.ok(fd, 'open returns a file descriptor')
43
-        var data = Buffer.alloc(7)
44
-        fs.read(fd, data, 0, 7, null, (err, bytesRead) => {
45
-          assert.error(err, 'no error')
46
-          assert.same(bytesRead, 7, 'read corrent number of bytes')
47
-          assert.same(data.toString(), 'i like ', 'read correct data')
48
-          fs.write(fd, Buffer.from('blue'), 0, 4, 7, (err, bytesWritten, buffer) => {
49
-            assert.error(err, 'no error')
50
-            assert.same(bytesWritten, 4, 'written correct number of bytes')
51
-            assert.same(buffer.toString(), 'blue', 'written correct data')
52
-            var data2 = Buffer.alloc(11)
53
-            fs.read(fd, data2, 0, 11, 0, (err, bytesRead) => {
54
-              assert.error(err, 'no error')
55
-              assert.same(data2.toString(), 'i like blue', "the file now contains 'i like blue'")
56
-              fs.close(fd, (err) => {
57
-                assert.error(err, 'no error')
58
-                blueDrive.readFile('orange.txt', 'utf-8', (err, data) => {
59
-                  assert.error(err, 'no error')
60
-                  assert.same(data, 'i like blue', 'readFile reads the changes correctly')
61
-                  replicate(orangeDrive, blueDrive, (err) => {
62
-                    assert.error(err, 'no error')
63
-                    fs.readFile(path.join(storage.orange, 'orange.txt'), 'utf-8', (err, data) => {
64
-                      assert.error(err, 'no error')
65
-                      assert.same(data, 'i like blue', 'correct changes are replicated')
66
-                      cleanup(destroy.orange, storage.orange).then(() => {
67
-                        cleanup(destroy.blue, storage.blue).then(next)
68
-                      })
69
-                    })
70
-                  })
71
-                })
72
-              })
73
-            })
74
-          })
75
-        })
76
-      })
77
-    }
78
-  })
79
-
80
-  // inspired by replication test for multifeed
81
-  context('replicate - write to mounted filesystem', (assert, next) => {
82
-    var feedsOnDisk = {
83
-      orange: tmp(),
84
-      blue: tmp()
85
-    }
86
-    var orangeDrive = KappaDrive(feedsOnDisk.orange)
87
-    var blueDrive = KappaDrive(feedsOnDisk.blue)
88
-    var storage = {}
89
-    var destroy = {}
90
-
91
-    function setup (drive, colour, cb) {
92
-      storage[colour] = tmp()
93
-      mount(drive, storage[colour]).then((destroyFn) => {
94
-        destroy[colour] = destroyFn
95
-        drive.ready(() => {
96
-          logLengths()
97
-          fs.writeFile(path.join(storage[colour], `${colour}.txt`), `i like ${colour}`, (err) => {
98
-            assert.error(err, `no error on writing ${colour}.txt`)
99
-            cb()
100
-          })
101
-        })
102
-      })
103
-    }
104
-
105
-    function logLengths () {
106
-      console.log('orange metadata', orangeDrive.metadata.length)
107
-      console.log('orange content ', orangeDrive.content.length)
108
-      if (blueDrive.metadata) {
109
-        console.log('blue metadata', blueDrive.metadata.length)
110
-        console.log('blue content ', blueDrive.content.length)
111
-      }
112
-    }
113
-    setup(orangeDrive, 'orange', function () {
114
-      setup(blueDrive, 'blue', function () {
115
-        logLengths()
116
-        replicate(orangeDrive, blueDrive, check)
117
-      })
118
-    })
119
-
120
-    function check (err) {
121
-      assert.error(err, 'no error on replicate')
122
-      orangeDrive.readdir('/', (err, files) => {
123
-        assert.error(err, 'no error on readDir')
124
-        assert.same(files.length, 2, 'orange drive has 2 files')
125
-        logLengths()
126
-        assert.ok(files.indexOf('blue.txt') > -1, 'orangedrive has file named blue.txt')
127
-        // orangeDrive.open('/blue.txt', 'r', (err, fd) => {
128
-          // assert.error(err, 'no error')
129
-          // var readBuf = Buffer.alloc('i like blue'.length)
130
-
131
-          orangeDrive.readFile('/blue.txt', (err, data) => {
132
-          // orangeDrive.read(fd, readBuf, 0, 11, null, (err, bytes, data) => {
133
-            assert.error(err, 'no error')
134
-            assert.same(data, Buffer.from('i like blue'), 'blue.txt on orange drive has correct content')
135
-
136
-            fs.readdir(storage.orange, (err, files) => {
137
-              assert.error(err, 'no error')
138
-              assert.same(files.length, 2, 'orange mounted volume has two files')
139
-              assert.ok(files.indexOf('blue.txt') > -1, 'orange mounted volume has file named blue.txt')
140
-
141
-              fs.readFile(path.join(storage.orange, 'blue.txt'), 'utf-8', (err, data) => {
142
-                assert.error(err, 'no error')
143
-                assert.same(data, 'i like blue', 'blue.txt in mounted volume has correct content')
144
-
145
-                blueDrive.readdir('/', (err, files) => {
146
-                  assert.error(err, 'no error')
147
-                  assert.same(files.length, 2, 'blue drive has 2 files')
148
-                  assert.ok(files.indexOf('orange.txt') > -1, 'bluedrive has file named orange.txt')
149
-
150
-                  blueDrive.open('orange.txt', 'r', (err, fd) => {
151
-                    assert.error(err, 'no error')
152
-                    blueDrive.read(fd, Buffer.alloc('i like orange'.length), 0, 14, null, (err, bytes, data) => {
153
-                      assert.error(err, 'no error')
154
-                      assert.same(data, Buffer.from('i like orange'), 'orange.txt on blue drive has correct content')
155
-
156
-                      fs.readdir(storage.blue, (err, files) => {
157
-                        assert.error(err, 'no error')
158
-                        assert.same(files.length, 2, 'orange mounted volume has two files')
159
-                        assert.ok(files.indexOf('orange.txt') > -1, 'blue mounted volume has file named orange.txt')
160
-
161
-                        fs.readFile(path.join(storage.blue, 'orange.txt'), 'utf-8', (err, data) => {
162
-                          assert.error(err, 'no error')
163
-                          assert.same(data, 'i like orange', 'orange.txt in mounted volume has correct content')
164
-
165
-                          cleanup(destroy.orange, storage.orange).then(() => {
166
-                            cleanup(destroy.blue, storage.blue).then(next)
167
-                          })
168
-                        })
169
-                      })
170
-                    })
171
-                  })
172
-                })
173
-              })
174
-            })
175
-          })
176
-        // })
177
-      })
178
-    }
179
-  })
180
-

+ 0
- 32
test/mount_hyperdrive.js View File

@@ -1,32 +0,0 @@
1
-#!/usr/bin/env node
2
-// This script is to mount a normal hyperdrive in the same way we would
3
-// mount a kappa-drive, to make it easy to compare thier behaviour.
4
-// Ideally we want to make all filesystem operations which are possible with
5
-// hyperdrive also possible with kappa-drive
6
-const minimist = require('minimist')
7
-const ram = require('random-access-memory')
8
-const path = require('path')
9
-
10
-const mount = require('..')
11
-const hyperdrive = require('hyperdrive')
12
-
13
-const STORAGE = (p) => path.resolve(p)
14
-
15
-const argv = minimist(process.argv.slice(2))
16
-var storage
17
-
18
-if (argv.db) {
19
-  storage = argv.db ? STORAGE(argv.db) : ram
20
-} else {
21
-  storage = ram
22
-}
23
-
24
-var mountdir = argv.mount || './mnt'
25
-var key = argv.key ? Buffer.from(argv.key, 'hex') : null
26
-
27
-var drive = hyperdrive(storage, key)
28
-
29
-drive.ready(() => {
30
-  mount(drive, mountdir)
31
-  // swarm(drive)
32
-})