mobiletto 1.1.7 → 1.1.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +9 -5
- package/drivers/b2/index.js +11 -7
- package/drivers/s3/index.js +4 -2
- package/index.js +33 -18
- package/package.json +3 -2
- package/test/api.spec.js +319 -306
- package/util/logger.js +1 -1
package/README.md
CHANGED
|
@@ -32,8 +32,8 @@ Mobiletto was designed to solve this problem. By coding your app to mobiletto's
|
|
|
32
32
|
change storage providers and know that your app's storage layer will behave identically.
|
|
33
33
|
|
|
34
34
|
### Extensive testing
|
|
35
|
-
All drivers are tested for identical behavior with
|
|
36
|
-
|
|
35
|
+
All drivers are tested for identical behavior with 60+ tests for each driver.
|
|
36
|
+
We test all drivers with every combination of:
|
|
37
37
|
* Encryption: both enabled and disabled
|
|
38
38
|
* Redis cache: both enabled and disabled
|
|
39
39
|
|
|
@@ -70,13 +70,13 @@ This code would run the same if the driver were `b2` or `local`.
|
|
|
70
70
|
const dirList = await bucket.list('some/dir/')
|
|
71
71
|
const everything = await bucket.list('', {recursive: true})
|
|
72
72
|
|
|
73
|
-
// write an entire file
|
|
73
|
+
// write an entire file
|
|
74
74
|
let bytesWritten = await bucket.writeFile('some/path', someBufferOfData)
|
|
75
75
|
|
|
76
76
|
// write a file from a stream/generator
|
|
77
77
|
bytesWritten = await bucket.write('some/path', streamOrGenerator)
|
|
78
78
|
|
|
79
|
-
// read an entire file
|
|
79
|
+
// read an entire file
|
|
80
80
|
// returns null if an exception would otherwise be thrown
|
|
81
81
|
const bufferOrNull = await bucket.safeReadFile('some/path')
|
|
82
82
|
|
|
@@ -160,9 +160,13 @@ A much more extensive example, showing most of the features offered:
|
|
|
160
160
|
const callback = (chunk) => { ... write chunk somewhere ... }
|
|
161
161
|
api.read(path, callback) // returns count of bytes read
|
|
162
162
|
|
|
163
|
-
// Read an entire file at once
|
|
163
|
+
// Read an entire file at once
|
|
164
164
|
const data = await api.readFile(path) // returns a byte Buffer of the file contents
|
|
165
165
|
|
|
166
|
+
// Read an entire file at once
|
|
167
|
+
// returns null if an exception would otherwise be thrown
|
|
168
|
+
const bufferOrNull = await bucket.safeReadFile('some/path')
|
|
169
|
+
|
|
166
170
|
// Write a file
|
|
167
171
|
// Provide a generator function that yields chunks of data
|
|
168
172
|
const generator = function* () {
|
package/drivers/b2/index.js
CHANGED
|
@@ -26,6 +26,7 @@ class StorageClient {
|
|
|
26
26
|
absoluteMinimumPartSize
|
|
27
27
|
recommendedPartSize
|
|
28
28
|
configuredPartSize
|
|
29
|
+
normalizeRegex
|
|
29
30
|
constructor(keyId, appKey, opts) {
|
|
30
31
|
if (!keyId || !appKey || !opts.bucket) throw new MobilettoError(`b2.StorageClient: key, secret and opts.bucket are required`)
|
|
31
32
|
this.b2 = new B2({
|
|
@@ -36,6 +37,7 @@ class StorageClient {
|
|
|
36
37
|
this.configuredPartSize = opts.partSize ? opts.partSize : -1
|
|
37
38
|
this.bucket = opts.bucket
|
|
38
39
|
this.delimiter = opts.delimiter || '/'
|
|
40
|
+
this.normalizeRegex = new RegExp(`${this.delimiter}{2,}`, 'g')
|
|
39
41
|
this.prefix = opts.prefix
|
|
40
42
|
? opts.prefix.endsWith(this.delimiter)
|
|
41
43
|
? opts.prefix
|
|
@@ -67,10 +69,12 @@ class StorageClient {
|
|
|
67
69
|
|
|
68
70
|
testConfig = async () => await this.b2_list('', false, null, {max: 1})
|
|
69
71
|
|
|
70
|
-
normalizePath = (path) =>
|
|
71
|
-
path.startsWith(this.prefix)
|
|
72
|
+
normalizePath = (path) => {
|
|
73
|
+
const p = (path.startsWith(this.prefix)
|
|
72
74
|
? path
|
|
73
|
-
: this.prefix + (path.startsWith(this.delimiter) ? path.substring(1) : path)
|
|
75
|
+
: this.prefix + (path.startsWith(this.delimiter) ? path.substring(1) : path))
|
|
76
|
+
return p.replaceAll(this.normalizeRegex, this.delimiter)
|
|
77
|
+
}
|
|
74
78
|
denormalizePath = (path) => {
|
|
75
79
|
const norm = path.startsWith(this.prefix) ? path.substring(this.prefix.length) : path
|
|
76
80
|
return norm.startsWith(this.delimiter) ? norm.substring(1) : norm
|
|
@@ -91,7 +95,7 @@ class StorageClient {
|
|
|
91
95
|
name: this.denormalizePath(f.fileName),
|
|
92
96
|
size: f.contentLength,
|
|
93
97
|
type: this.b2type(f),
|
|
94
|
-
|
|
98
|
+
b2id: f.fileId
|
|
95
99
|
}
|
|
96
100
|
}
|
|
97
101
|
|
|
@@ -135,7 +139,7 @@ class StorageClient {
|
|
|
135
139
|
const list = await this.processList(pth, response, visitor)
|
|
136
140
|
if (!optsDir && !firstResult && list.length > 0) {
|
|
137
141
|
firstResult = list[0]
|
|
138
|
-
if (list[0].name.endsWith(
|
|
142
|
+
if (list[0].name.endsWith(this.delimiter)) {
|
|
139
143
|
dirDiscovered = true
|
|
140
144
|
} else if (!dirDiscovered && list.length > 1 && list[1].name.startsWith(list[0].name)) {
|
|
141
145
|
files.push(list[0])
|
|
@@ -266,7 +270,7 @@ class StorageClient {
|
|
|
266
270
|
try {
|
|
267
271
|
const stream = await this.b2.downloadFileById({
|
|
268
272
|
bucketId: this.bucket,
|
|
269
|
-
fileId: meta.
|
|
273
|
+
fileId: meta.b2id,
|
|
270
274
|
responseType: 'stream'
|
|
271
275
|
})
|
|
272
276
|
return await readStream(stream.data, callback, endCallback)
|
|
@@ -344,7 +348,7 @@ class StorageClient {
|
|
|
344
348
|
const response = await this.b2.listFileVersions({
|
|
345
349
|
bucketId: this.bucket,
|
|
346
350
|
startFileName: normPath,
|
|
347
|
-
startFileId: meta.
|
|
351
|
+
startFileId: meta.b2id,
|
|
348
352
|
prefix: this.prefix,
|
|
349
353
|
delimiter: this.delimiter,
|
|
350
354
|
maxFileCount: 1000
|
package/drivers/s3/index.js
CHANGED
|
@@ -28,12 +28,14 @@ class StorageClient {
|
|
|
28
28
|
bucket
|
|
29
29
|
prefix
|
|
30
30
|
delimiter
|
|
31
|
+
normalizeRegex
|
|
31
32
|
constructor(key, secret, opts) {
|
|
32
33
|
if (!key || !secret || !opts || !opts.bucket) {
|
|
33
34
|
throw new MobilettoError('s3.StorageClient: key, secret, and opts.bucket are required')
|
|
34
35
|
}
|
|
35
36
|
this.bucket = opts.bucket
|
|
36
37
|
const delim = this.delimiter = opts.delimiter || DEFAULT_DELIMITER
|
|
38
|
+
this.normalizeRegex = new RegExp(`${this.delimiter}{2,}`, 'g')
|
|
37
39
|
this.prefix = opts.prefix || DEFAULT_PREFIX
|
|
38
40
|
? opts.prefix.endsWith(delim)
|
|
39
41
|
? opts.prefix
|
|
@@ -64,7 +66,7 @@ class StorageClient {
|
|
|
64
66
|
try {
|
|
65
67
|
return await this._list(path, recursive, visitor)
|
|
66
68
|
} catch (e) {
|
|
67
|
-
if (e instanceof MobilettoNotFoundError && !recursive && path.includes(
|
|
69
|
+
if (e instanceof MobilettoNotFoundError && !recursive && path.includes(this.delimiter)) {
|
|
68
70
|
// are we trying to list a single file?
|
|
69
71
|
const objects = await this._list(dirname(path), false)
|
|
70
72
|
const found = objects.find(o => o.name === path)
|
|
@@ -151,7 +153,7 @@ class StorageClient {
|
|
|
151
153
|
const p = (path.startsWith(this.prefix)
|
|
152
154
|
? path
|
|
153
155
|
: this.prefix + (path.startsWith(this.delimiter) ? path.substring(1) : path))
|
|
154
|
-
return p.replaceAll(
|
|
156
|
+
return p.replaceAll(this.normalizeRegex, this.delimiter)
|
|
155
157
|
}
|
|
156
158
|
denormalizeKey = (key) => {
|
|
157
159
|
return key.startsWith(this.prefix)
|
package/index.js
CHANGED
|
@@ -9,7 +9,7 @@ const randomstring = require('randomstring')
|
|
|
9
9
|
|
|
10
10
|
const crypt = require('./util/crypt')
|
|
11
11
|
const {DEFAULT_CRYPT_ALGO, normalizeKey, normalizeIV, encrypt, decrypt} = require("./util/crypt")
|
|
12
|
-
const LRU = require("lru-cache")
|
|
12
|
+
const LRU = require("lru-cache")
|
|
13
13
|
|
|
14
14
|
const DIR_ENT_DIR_SUFFIX = '__.dirent'
|
|
15
15
|
const DIR_ENT_FILE_PREFIX = 'dirent__'
|
|
@@ -209,10 +209,14 @@ const UTILITY_FUNCTIONS = {
|
|
|
209
209
|
},
|
|
210
210
|
write: (client) => async (path, data) => {
|
|
211
211
|
logger.debug(`util.write(${path}) starting ...`)
|
|
212
|
+
const p = path.startsWith('/') ? path.substring(1) : path
|
|
213
|
+
if (p !== path) {
|
|
214
|
+
logger.debug(`util.write(${path}) removed leading ${this.delimiter}`)
|
|
215
|
+
}
|
|
212
216
|
// noinspection JSUnresolvedFunction
|
|
213
|
-
const bytesWritten = await client.driver_write(
|
|
217
|
+
const bytesWritten = await client.driver_write(p, data)
|
|
214
218
|
await client.flush()
|
|
215
|
-
logger.debug(`util.write(${
|
|
219
|
+
logger.debug(`util.write(${p}) wrote ${bytesWritten} bytes`)
|
|
216
220
|
return bytesWritten
|
|
217
221
|
},
|
|
218
222
|
writeFile: (client) => async (path, data) => {
|
|
@@ -512,36 +516,50 @@ async function mobiletto (driverPath, key, secret, opts, encryption = null) {
|
|
|
512
516
|
return thing
|
|
513
517
|
}
|
|
514
518
|
|
|
515
|
-
async function tryParentDirForSingleFile (
|
|
519
|
+
async function tryParentDirForSingleFile (p, visitor, e) {
|
|
516
520
|
// it might be a single file, try listing the parent dir
|
|
517
|
-
const parentDirent = direntDir(
|
|
518
|
-
entries = await client.list(parentDirent
|
|
521
|
+
const parentDirent = direntDir(dirname(p))
|
|
522
|
+
entries = await client.list(parentDirent)
|
|
519
523
|
const objects = await _loadMeta(parentDirent, entries)
|
|
520
524
|
const found = objects.find(o => o.name === p)
|
|
521
525
|
if (found) {
|
|
522
526
|
if (visitor) {
|
|
523
527
|
await visitor(found)
|
|
524
528
|
}
|
|
525
|
-
logger.debug(`tryParentDirForSingleFile(${
|
|
529
|
+
logger.debug(`tryParentDirForSingleFile(${p}) found ${found.name}`)
|
|
526
530
|
return cacheAndReturn([found])
|
|
527
531
|
}
|
|
528
|
-
logger.debug(`tryParentDirForSingleFile(${
|
|
529
|
-
throw e === null ? new MobilettoNotFoundError(
|
|
532
|
+
logger.debug(`tryParentDirForSingleFile(${p}) nothing found! e=${e}`)
|
|
533
|
+
throw e === null ? new MobilettoNotFoundError(p) : e
|
|
530
534
|
}
|
|
531
535
|
|
|
532
536
|
if (cached) {
|
|
533
537
|
entries = cached
|
|
534
538
|
} else {
|
|
535
539
|
try {
|
|
536
|
-
entries = await client.list(dirent
|
|
540
|
+
entries = await _loadMeta(dirent, await client.list(dirent))
|
|
537
541
|
} catch (e) {
|
|
538
542
|
if (e instanceof MobilettoNotFoundError && p.includes('/')) {
|
|
539
|
-
return await tryParentDirForSingleFile(
|
|
543
|
+
return await tryParentDirForSingleFile(p, visitor, e)
|
|
544
|
+
}
|
|
545
|
+
}
|
|
546
|
+
if (recursive) {
|
|
547
|
+
const dirs = entries.filter(obj => obj.type === M_DIR)
|
|
548
|
+
while (dirs.length > 0) {
|
|
549
|
+
const dir = dirs.shift()
|
|
550
|
+
const subdir = direntDir(dir.name)
|
|
551
|
+
const subdirListing = await client.list(subdir)
|
|
552
|
+
if (subdirListing && subdirListing.length > 0) {
|
|
553
|
+
const subdirEntries = await _loadMeta(subdir, subdirListing)
|
|
554
|
+
entries.push(...subdirEntries)
|
|
555
|
+
const moreDirs = subdirEntries.filter(obj => obj.type === M_DIR)
|
|
556
|
+
dirs.unshift(...moreDirs)
|
|
557
|
+
}
|
|
540
558
|
}
|
|
541
559
|
}
|
|
542
560
|
}
|
|
543
561
|
if (entries.length === 0 && p.includes('/')) {
|
|
544
|
-
return await tryParentDirForSingleFile(
|
|
562
|
+
return await tryParentDirForSingleFile(p, visitor, null)
|
|
545
563
|
}
|
|
546
564
|
if (cache) {
|
|
547
565
|
cache.set(cacheKey, entries).then(
|
|
@@ -553,14 +571,11 @@ async function mobiletto (driverPath, key, secret, opts, encryption = null) {
|
|
|
553
571
|
return []
|
|
554
572
|
}
|
|
555
573
|
if (visitor) {
|
|
556
|
-
const
|
|
557
|
-
for (const obj of objects) {
|
|
574
|
+
for (const obj of entries) {
|
|
558
575
|
await visitor(obj)
|
|
559
576
|
}
|
|
560
|
-
return objects
|
|
561
|
-
} else {
|
|
562
|
-
return _loadMeta(dirent, entries)
|
|
563
577
|
}
|
|
578
|
+
return entries
|
|
564
579
|
},
|
|
565
580
|
metadata: _metadata(client),
|
|
566
581
|
read: async (path, callback) => {
|
|
@@ -584,7 +599,7 @@ async function mobiletto (driverPath, key, secret, opts, encryption = null) {
|
|
|
584
599
|
throw new MobilettoError('write: error writing dirent file')
|
|
585
600
|
}
|
|
586
601
|
p = dirname(p)
|
|
587
|
-
if (p === '.' || p === ''
|
|
602
|
+
if (p === '.' || p === '') {
|
|
588
603
|
break
|
|
589
604
|
}
|
|
590
605
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mobiletto",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.10",
|
|
4
4
|
"description": "A storage layer that presents a uniform interface to Amazon S3, Backblaze B2, and local storage",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"keywords": [
|
|
@@ -8,7 +8,8 @@
|
|
|
8
8
|
"s3",
|
|
9
9
|
"b2",
|
|
10
10
|
"simple",
|
|
11
|
-
"filesystem"
|
|
11
|
+
"filesystem",
|
|
12
|
+
"mobiletto"
|
|
12
13
|
],
|
|
13
14
|
"homepage": "https://github.com/cobbzilla/mobiletto",
|
|
14
15
|
"author": "Jonathan Cobb <bqppl0m2@duck.com> (https://github.com/cobbzilla)",
|
package/test/api.spec.js
CHANGED
|
@@ -119,363 +119,376 @@ const REDIS_DISABLED = {
|
|
|
119
119
|
return newConfig
|
|
120
120
|
}
|
|
121
121
|
}
|
|
122
|
+
|
|
122
123
|
const redisTests = () => [REDIS_ENABLED, REDIS_DISABLED]
|
|
124
|
+
// const redisTests = () => [REDIS_ENABLED]
|
|
125
|
+
// const redisTests = () => [REDIS_DISABLED]
|
|
123
126
|
|
|
124
127
|
for (const redisSetup of redisTests()) {
|
|
125
|
-
|
|
128
|
+
if (!redisSetup.enabled) continue
|
|
126
129
|
|
|
127
130
|
for (const driverName of DRIVER_NAMES) {
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
131
|
+
// For testing single drivers
|
|
132
|
+
// if (driverName !== 'local') continue
|
|
133
|
+
|
|
134
|
+
const driverTest = `${driverName} [${redisSetup.name}]`
|
|
135
|
+
const config = redisSetup.config(DRIVER_CONFIG[driverName])
|
|
136
|
+
const nonexistentFile = 'random_file_that_does_not_exist_' + rand(100) + '_' + Date.now()
|
|
137
|
+
const tempFilename = (name, i) => name + (i > 0 ? '_' + i : '')
|
|
138
|
+
describe(`${driverTest} test`, () => {
|
|
139
|
+
beforeEach ((done) => {
|
|
140
|
+
redis.flushAll().then(
|
|
141
|
+
() => { logger.info(`${driverTest} - flushed redis`) },
|
|
142
|
+
(e) => {
|
|
143
|
+
logger.error(`${driverTest} - error flushing redis: ${e}`)
|
|
144
|
+
throw e
|
|
145
|
+
}
|
|
146
|
+
).finally(() => done())
|
|
147
|
+
})
|
|
148
|
+
|
|
149
|
+
describe(`${driverTest} - create api client`, () => {
|
|
150
|
+
it("should validate the config and return an API object", async () => {
|
|
151
|
+
try {
|
|
152
|
+
const api = await mobiletto(driverName, config.key, config.secret, config.opts)
|
|
153
|
+
should().exist(api, 'expected API object to exist')
|
|
154
|
+
} catch (e) {
|
|
155
|
+
logger.error(`error creating API: ${e} ${JSON.stringify(e)}`)
|
|
156
|
+
throw e
|
|
157
|
+
}
|
|
144
158
|
})
|
|
159
|
+
})
|
|
145
160
|
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
} catch (e) {
|
|
152
|
-
logger.error(`error creating API: ${e} ${JSON.stringify(e)}`)
|
|
153
|
-
throw e
|
|
154
|
-
}
|
|
155
|
-
})
|
|
161
|
+
describe(`${driverTest} - listing with no arguments returns some results`, () => {
|
|
162
|
+
it("should return some results from a default listing", async () => {
|
|
163
|
+
const api = await mobiletto(driverName, config.key, config.secret, config.opts)
|
|
164
|
+
const results = await api.list()
|
|
165
|
+
expect(results).to.have.lengthOf.greaterThan(0, 'expected some results in the default listing')
|
|
156
166
|
})
|
|
167
|
+
})
|
|
157
168
|
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
169
|
+
describe(`${driverTest} - write a file, read file, read metadata, delete file`, () => {
|
|
170
|
+
// some random data, plus a bit extra
|
|
171
|
+
const size = (READ_SZ * TEMP_SZ_MULTIPLE) + Math.floor(Math.random() * (READ_SZ/2))
|
|
172
|
+
const randomData = rand(size)
|
|
173
|
+
const fileSuffix = '' + Date.now()
|
|
174
|
+
let fixture
|
|
175
|
+
before((done) => {
|
|
176
|
+
const name = `test_file_${fileSuffix}`
|
|
177
|
+
connect(driverName, config.key, config.secret, config.opts)
|
|
178
|
+
.then(api => { fixture = {api, name, randomData} })
|
|
179
|
+
.finally(done)
|
|
180
|
+
})
|
|
181
|
+
it("should write a file", async () => {
|
|
182
|
+
const response = await writeRandomFile(fixture, size)
|
|
183
|
+
expect(response).to.equal(size, 'expected write API to return correct number of bytes written')
|
|
184
|
+
})
|
|
185
|
+
it("should read the file we just wrote", async () => {
|
|
186
|
+
const data = await fixture.api.readFile(fixture.name)
|
|
187
|
+
expect(data.length).is.equal(size, 'expected read API to return correct number of bytes read')
|
|
188
|
+
expect(data.toString()).to.equal(fixture.randomData, 'expected to read back the same data we wrote')
|
|
189
|
+
})
|
|
190
|
+
it("should load metadata on the file we just wrote", async () => {
|
|
191
|
+
await assertMeta(fixture.api, fixture.name, fixture.randomData.length)
|
|
164
192
|
})
|
|
193
|
+
it("should delete the file we just wrote", async () => {
|
|
194
|
+
const removed = await fixture.api.remove(fixture.name)
|
|
195
|
+
expect(!!removed).to.be.true
|
|
196
|
+
})
|
|
197
|
+
it("loading metadata on the file we wrote now fails", async () => {
|
|
198
|
+
await assertMetaFail(fixture.api, fixture.name)
|
|
199
|
+
})
|
|
200
|
+
it("loading metadata on the file we wrote using safeMeta does not fail but returns null", async () => {
|
|
201
|
+
await assertSafeMetaNull(fixture.api, fixture.name)
|
|
202
|
+
})
|
|
203
|
+
})
|
|
165
204
|
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
205
|
+
for (const encryption of encryptionTests()) {
|
|
206
|
+
const encDesc = encryption ? '(with encryption)' : '(without encryption)'
|
|
207
|
+
describe(`${driverTest} - ${encDesc} fail to write and delete files in readOnly mode`, () => {
|
|
208
|
+
// describe(`${driverTest} - ENC fail to write and delete files in readOnly mode`, () => {
|
|
209
|
+
// const encryption = {key: rand(32)}
|
|
210
|
+
const size = 16
|
|
169
211
|
const randomData = rand(size)
|
|
170
212
|
const fileSuffix = '' + Date.now()
|
|
171
213
|
let fixture
|
|
172
214
|
before((done) => {
|
|
173
215
|
const name = `test_file_${fileSuffix}`
|
|
174
|
-
|
|
216
|
+
const opts = Object.assign({}, config.opts, {readOnly: true})
|
|
217
|
+
connect(driverName, config.key, config.secret, opts, encryption)
|
|
175
218
|
.then(api => { fixture = {api, name, randomData} })
|
|
219
|
+
.catch(err => { throw err })
|
|
176
220
|
.finally(done)
|
|
177
221
|
})
|
|
178
|
-
it("should write a file", async () => {
|
|
222
|
+
it("should try to write a file and fail", async () => {
|
|
179
223
|
const response = await writeRandomFile(fixture, size)
|
|
180
|
-
expect(response).to.
|
|
224
|
+
expect(response).to.be.false
|
|
181
225
|
})
|
|
182
|
-
it("should read the file we
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
226
|
+
it("should fail to read the file we did not write", async () => {
|
|
227
|
+
try {
|
|
228
|
+
await fixture.api.readFile(fixture.name)
|
|
229
|
+
assert.fail('should not have been able to read non-existent file that we did not write')
|
|
230
|
+
} catch (e) {
|
|
231
|
+
if (!(e instanceof MobilettoNotFoundError)) {
|
|
232
|
+
assert.fail(`unexpected error: ${e} trying to read non-existent file`)
|
|
233
|
+
}
|
|
234
|
+
}
|
|
186
235
|
})
|
|
187
|
-
it("should load metadata on the file we
|
|
188
|
-
|
|
236
|
+
it("should fail to load metadata on the file we did not write", async () => {
|
|
237
|
+
try {
|
|
238
|
+
await assertMeta(fixture.api, fixture.name, fixture.randomData.length)
|
|
239
|
+
assert.fail('should not have been able to read metadata for non-existent file that we did not write')
|
|
240
|
+
} catch (e) {
|
|
241
|
+
if (!(e instanceof MobilettoNotFoundError)) {
|
|
242
|
+
assert.fail(`unexpected error: ${e} trying to read metadata on non-existent file`)
|
|
243
|
+
}
|
|
244
|
+
}
|
|
189
245
|
})
|
|
190
|
-
it("should delete the file we
|
|
246
|
+
it("should fail to delete the file we did not write", async () => {
|
|
191
247
|
const removed = await fixture.api.remove(fixture.name)
|
|
192
|
-
expect(!!removed).to.be.
|
|
193
|
-
})
|
|
194
|
-
it("loading metadata on the file we wrote now fails", async () => {
|
|
195
|
-
await assertMetaFail(fixture.api, fixture.name)
|
|
196
|
-
})
|
|
197
|
-
it("loading metadata on the file we wrote using safeMeta does not fail but returns null", async () => {
|
|
198
|
-
await assertSafeMetaNull(fixture.api, fixture.name)
|
|
248
|
+
expect(!!removed).to.be.false
|
|
199
249
|
})
|
|
200
250
|
})
|
|
251
|
+
}
|
|
201
252
|
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
assert.fail('should not have been able to read metadata for non-existent file that we did not write')
|
|
237
|
-
} catch (e) {
|
|
238
|
-
if (!(e instanceof MobilettoNotFoundError)) {
|
|
239
|
-
assert.fail(`unexpected error: ${e} trying to read metadata on non-existent file`)
|
|
240
|
-
}
|
|
241
|
-
}
|
|
242
|
-
})
|
|
243
|
-
it("should fail to delete the file we did not write", async () => {
|
|
244
|
-
const removed = await fixture.api.remove(fixture.name)
|
|
245
|
-
expect(!!removed).to.be.false
|
|
246
|
-
})
|
|
247
|
-
})
|
|
248
|
-
}
|
|
253
|
+
describe(`${driverTest} - write an encrypted file, read file, read metadata, delete file`, () => {
|
|
254
|
+
// some random data, plus a bit extra
|
|
255
|
+
const size = (READ_SZ * TEMP_SZ_MULTIPLE) + Math.floor(Math.random() * (READ_SZ/2))
|
|
256
|
+
const randomData = rand(size)
|
|
257
|
+
const fileSuffix = '' + Date.now()
|
|
258
|
+
const encryptionKey = rand(32)
|
|
259
|
+
let fixture
|
|
260
|
+
before((done) => {
|
|
261
|
+
const name = `test_file_${fileSuffix}`
|
|
262
|
+
mobiletto(driverName, config.key, config.secret, config.opts, {key: encryptionKey})
|
|
263
|
+
.then(api => { fixture = {api, name, randomData} })
|
|
264
|
+
.catch((err) => { throw err })
|
|
265
|
+
.finally(done)
|
|
266
|
+
})
|
|
267
|
+
it("should write an encrypted file", async () => {
|
|
268
|
+
const bytesWritten = await writeRandomFile(fixture, size)
|
|
269
|
+
expect(bytesWritten).is.equal(size, 'expected write API to return correct number of bytes written')
|
|
270
|
+
})
|
|
271
|
+
it("should read the encrypted file we just wrote", async () => {
|
|
272
|
+
const data = await fixture.api.readFile(fixture.name)
|
|
273
|
+
expect(data.length).is.equal(size, 'expected read API to return correct number of bytes read')
|
|
274
|
+
expect(data.toString()).to.equal(fixture.randomData, 'expected to read back the same data we wrote')
|
|
275
|
+
})
|
|
276
|
+
it("should load metadata on the encrypted file we just wrote", async () => {
|
|
277
|
+
await assertMeta(fixture.api, fixture.name, fixture.randomData.length)
|
|
278
|
+
})
|
|
279
|
+
it("should delete the encrypted file we just wrote", async () => {
|
|
280
|
+
const removed = await fixture.api.remove(fixture.name)
|
|
281
|
+
expect(!!removed).to.be.true
|
|
282
|
+
})
|
|
283
|
+
it("loading metadata on the encrypted file we wrote now fails", async () => {
|
|
284
|
+
await assertMetaFail(fixture.api, fixture.name)
|
|
285
|
+
})
|
|
286
|
+
})
|
|
249
287
|
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
288
|
+
for (const encryption of encryptionTests()) {
|
|
289
|
+
const encDesc = encryption ? '(with encryption)' : '(without encryption)'
|
|
290
|
+
const mirrorDriver = pickAnotherDriver(driverName)
|
|
291
|
+
// const mirrorDriver = 'local' // for hard-coding the mirror driver
|
|
292
|
+
const mirrorConfig = DRIVER_CONFIG[mirrorDriver]
|
|
293
|
+
const mirrorDest = `mirrorDest_${rand(5)}/`
|
|
294
|
+
describe(`${driverTest} - ${encDesc} write files in a new dir, read metadata, mirror to another place (${mirrorDriver}), verify mirror, recursively delete from both`, () => {
|
|
295
|
+
// to force encryption or no encryption, uncomment one of these:
|
|
296
|
+
// const encryption = {key: rand(32)}
|
|
297
|
+
// const encryption = null
|
|
298
|
+
|
|
299
|
+
// a random directory, a subdirectory, and files within it
|
|
300
|
+
const randomParent = `testRPD_${rand(2)}/rand_${rand(4)}`
|
|
301
|
+
const subdirName = `subdir_` + Date.now()
|
|
302
|
+
const fullSubdirPath = `${randomParent}/${subdirName}`
|
|
303
|
+
const randomPath = `${fullSubdirPath}/random_file_${Date.now()}`
|
|
304
|
+
const randomStreamFileSize = READ_SZ * 10
|
|
305
|
+
const randomStreamFileData = crypto.randomBytes(randomStreamFileSize)
|
|
306
|
+
//const fileCount = 3 + Math.floor(Math.random() * 10)
|
|
307
|
+
const fileCount = 2
|
|
256
308
|
let fixture
|
|
257
309
|
before((done) => {
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
310
|
+
mobiletto(driverName, config.key, config.secret, config.opts, encryption)
|
|
311
|
+
.then(api => {
|
|
312
|
+
// const mirrorEnc = { key: rand(32) }
|
|
313
|
+
const mirrorEnc = null
|
|
314
|
+
mobiletto(mirrorDriver, mirrorConfig.key, mirrorConfig.secret, mirrorConfig.opts, mirrorEnc)
|
|
315
|
+
.then(mirrorApi => {
|
|
316
|
+
fixture = {api, mirrorApi, name: randomPath}
|
|
317
|
+
})
|
|
318
|
+
.catch((err) => {
|
|
319
|
+
throw err
|
|
320
|
+
})
|
|
321
|
+
.finally(done)
|
|
322
|
+
})
|
|
261
323
|
.catch((err) => { throw err })
|
|
262
|
-
.finally(done)
|
|
263
324
|
})
|
|
264
|
-
it(
|
|
265
|
-
|
|
266
|
-
|
|
325
|
+
it(`should write ${fileCount} files in a new directory`, async () => {
|
|
326
|
+
// return one chunk of random data
|
|
327
|
+
function* dataGenerator() { yield rand(READ_SZ) }
|
|
328
|
+
for (let i = 0; i < fileCount; i++) {
|
|
329
|
+
const bytesWritten = await fixture.api.write(tempFilename(fixture.name, i), dataGenerator())
|
|
330
|
+
expect(bytesWritten).to.equal(READ_SZ, 'expected write API to return correct number of bytes written')
|
|
331
|
+
}
|
|
267
332
|
})
|
|
268
|
-
it(
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
333
|
+
it('should write a file in a new directory using a stream', async () => {
|
|
334
|
+
// create a random temp file, write it
|
|
335
|
+
const tempFile = `/tmp/${randomstring.generate(10)}_cool_${Date.now()}`
|
|
336
|
+
fs.writeFileSync(tempFile, randomStreamFileData)
|
|
337
|
+
const reader = fs.createReadStream(tempFile)
|
|
338
|
+
const streamFile = fixture.name + '_stream'
|
|
339
|
+
const bytesWritten = await fixture.api.write(streamFile, reader)
|
|
340
|
+
expect(bytesWritten).to.equal(randomStreamFileSize, 'expected write API to return correct number of bytes written for STREAM')
|
|
272
341
|
})
|
|
273
|
-
it("should
|
|
274
|
-
|
|
342
|
+
it("should successfully read and then remove the file that was stream-written", async () => {
|
|
343
|
+
const streamFile = fixture.name + '_stream'
|
|
344
|
+
const singleFile = (await fixture.api.readFile(streamFile))
|
|
345
|
+
expect(singleFile).to.have.lengthOf(randomStreamFileSize)
|
|
346
|
+
for (let i = 0; i < singleFile.length; i++) {
|
|
347
|
+
expect(singleFile[i]).to.equal(randomStreamFileData[i])
|
|
348
|
+
}
|
|
349
|
+
const removal = await fixture.api.remove(streamFile)
|
|
350
|
+
expect(removal).to.equal(streamFile, `expected stream file to be deleted, but was: ${removal}`)
|
|
275
351
|
})
|
|
276
|
-
it("should
|
|
277
|
-
const
|
|
352
|
+
it("should successfully list a file individually", async () => {
|
|
353
|
+
const singleFile = await fixture.api.list(fixture.name)
|
|
354
|
+
expect(singleFile).to.have.lengthOf(1)
|
|
355
|
+
expect(singleFile[0]).to.have.property('name', fixture.name)
|
|
356
|
+
})
|
|
357
|
+
it("should successfully list files in the base directory", async () => {
|
|
358
|
+
const baseListing = await fixture.api.list()
|
|
359
|
+
expect(baseListing).to.have.lengthOf.greaterThanOrEqual(1)
|
|
360
|
+
expect(baseListing.find(o => o.name === dirname(randomParent) || o.name === dirname(randomParent)+'/')).to.not.be.null
|
|
361
|
+
})
|
|
362
|
+
it("should successfully list files in a subdirectory, with or without a trailing slash", async () => {
|
|
363
|
+
const noSlash = await fixture.api.list(randomParent)
|
|
364
|
+
expect(noSlash).to.have.lengthOf.greaterThanOrEqual(1)
|
|
365
|
+
const withSlash = await fixture.api.list(randomParent+'/')
|
|
366
|
+
expect(withSlash).to.have.lengthOf.greaterThanOrEqual(1)
|
|
367
|
+
for (const f of noSlash) {
|
|
368
|
+
expect(withSlash.find(o => o.name === f.name)).to.not.be.null
|
|
369
|
+
}
|
|
370
|
+
for (const f of withSlash) {
|
|
371
|
+
expect(noSlash.find(o => o.name === f.name)).to.not.be.null
|
|
372
|
+
}
|
|
373
|
+
})
|
|
374
|
+
it("should successfully recursively list files and see all correct subdirectories and files", async () => {
|
|
375
|
+
const allFiles = await fixture.api.list(randomParent, { recursive: true })
|
|
376
|
+
expect(allFiles).to.have.lengthOf(fileCount + 1)
|
|
377
|
+
expect(allFiles.find(f => f.name === fullSubdirPath && f.type === M_DIR)).to.not.be.null
|
|
378
|
+
expect(allFiles.find(f => f.name === fixture.name && f.type === M_FILE)).to.not.be.null
|
|
379
|
+
for (let i = 0; i < fileCount; i++) {
|
|
380
|
+
expect(allFiles.find(f => f.name === tempFilename(fixture.name, i) && f.type === M_FILE)).to.not.be.null
|
|
381
|
+
}
|
|
382
|
+
})
|
|
383
|
+
it("should load metadata for one of the new files", async () => {
|
|
384
|
+
await assertMeta(fixture.api, fixture.name, READ_SZ)
|
|
385
|
+
})
|
|
386
|
+
it("should see correct types on objects returned from a listing of the new directory", async () => {
|
|
387
|
+
const objects = await fixture.api.list(randomParent)
|
|
388
|
+
expect(objects).to.have.lengthOf(1)
|
|
389
|
+
expect(objects[0]).to.have.property('type', M_DIR, `subdir should have type ${M_DIR}`)
|
|
390
|
+
})
|
|
391
|
+
it("should see correct types on objects returned from a listing of the subdirectory", async () => {
|
|
392
|
+
const objects = await fixture.api.list(`${randomParent}/${subdirName}`)
|
|
393
|
+
expect(objects).to.have.lengthOf(fileCount)
|
|
394
|
+
for (let i = 0; i < fileCount; i++) {
|
|
395
|
+
// we should find all the files, and they should all have the correct type
|
|
396
|
+
expect(objects
|
|
397
|
+
.find(o => (o.type === M_FILE && o.name === tempFilename(fixture.name, i)))
|
|
398
|
+
).to.not.be.null
|
|
399
|
+
}
|
|
400
|
+
})
|
|
401
|
+
it(`should mirror its subdirectory (${driverName}/${randomParent}) to another place (${mirrorDriver}/${mirrorDest})`, async () => {
|
|
402
|
+
const results = await fixture.mirrorApi.mirror(fixture.api, mirrorDest, randomParent)
|
|
403
|
+
expect(results).to.have.property('errors', 0, 'expected no errors in mirroring')
|
|
404
|
+
expect(results).to.have.property('success').greaterThan(0, 'expected some successes in mirroring')
|
|
405
|
+
})
|
|
406
|
+
it("should see the same files mirrored both places", async () => {
|
|
407
|
+
const originalThings = await fixture.api.list(fullSubdirPath)
|
|
408
|
+
const mirrorPath = `${mirrorDest}${subdirName}`
|
|
409
|
+
const mirrorThings = await fixture.mirrorApi.list(mirrorPath)
|
|
410
|
+
expect(originalThings.length === mirrorThings.length).to.be.true
|
|
411
|
+
|
|
412
|
+
const intersection = originalThings
|
|
413
|
+
.filter(orig => mirrorThings
|
|
414
|
+
.find(m => basename(m.name) === basename(orig.name)))
|
|
415
|
+
expect(intersection.length === originalThings.length).to.be.true
|
|
416
|
+
})
|
|
417
|
+
it("loading metadata on a mirrored file succeeds", async () => {
|
|
418
|
+
const destPath = mirrorDest + subdirName + '/' + basename(fixture.name)
|
|
419
|
+
await assertMeta(fixture.mirrorApi, destPath, READ_SZ)
|
|
420
|
+
})
|
|
421
|
+
it("should recursively delete the mirrored data", async () => {
|
|
422
|
+
const recursive = true
|
|
423
|
+
const removed = await fixture.mirrorApi.remove(mirrorDest, {recursive})
|
|
424
|
+
expect(!!removed).to.be.true
|
|
425
|
+
})
|
|
426
|
+
it("should recursively delete the directory and file we just created", async () => {
|
|
427
|
+
const recursive = true
|
|
428
|
+
const removed = await fixture.api.remove(randomParent, {recursive})
|
|
278
429
|
expect(!!removed).to.be.true
|
|
279
430
|
})
|
|
280
|
-
it("loading metadata on the
|
|
431
|
+
it("loading metadata on the file we wrote now fails", async () => {
|
|
281
432
|
await assertMetaFail(fixture.api, fixture.name)
|
|
282
433
|
})
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
const encDesc = encryption ? '(with encryption)' : '(without encryption)'
|
|
287
|
-
// const mirrorDriver = pickAnotherDriver(driverName)
|
|
288
|
-
const mirrorDriver = 'local' // for hard-coding the mirror driver
|
|
289
|
-
const mirrorConfig = DRIVER_CONFIG[mirrorDriver]
|
|
290
|
-
const mirrorDest = `mirrorDest_${rand(5)}/`
|
|
291
|
-
describe(`${driverTest} - ${encDesc} write files in a new dir, read metadata, mirror to another place (${mirrorDriver}), verify mirror, recursively delete from both`, () => {
|
|
292
|
-
// describe(`${driverTest} - ENCRYPTION write files in a new dir, read metadata, recursively delete`, () => {
|
|
293
|
-
// const encryption = {key: rand(32)}
|
|
294
|
-
// const encryption = null
|
|
295
|
-
// a random directory and file within it
|
|
296
|
-
const randomParent = `testRPD_${rand(2)}/rand_${rand(4)}`
|
|
297
|
-
const subdirName = `subdir_` + Date.now()
|
|
298
|
-
const fullSubdirPath = `${randomParent}/${subdirName}`
|
|
299
|
-
const randomPath = `${fullSubdirPath}/random_file_${Date.now()}`
|
|
300
|
-
const randomStreamFileSize = READ_SZ * 10
|
|
301
|
-
const randomStreamFileData = crypto.randomBytes(randomStreamFileSize)
|
|
302
|
-
//const fileCount = 3 + Math.floor(Math.random() * 10)
|
|
303
|
-
const fileCount = 2
|
|
304
|
-
let fixture
|
|
305
|
-
before((done) => {
|
|
306
|
-
mobiletto(driverName, config.key, config.secret, config.opts, encryption)
|
|
307
|
-
.then(api => {
|
|
308
|
-
// const mirrorEnc = { key: rand(32) }
|
|
309
|
-
const mirrorEnc = null
|
|
310
|
-
mobiletto(mirrorDriver, mirrorConfig.key, mirrorConfig.secret, mirrorConfig.opts, mirrorEnc)
|
|
311
|
-
.then(mirrorApi => {
|
|
312
|
-
fixture = {api, mirrorApi, name: randomPath}
|
|
313
|
-
})
|
|
314
|
-
.catch((err) => {
|
|
315
|
-
throw err
|
|
316
|
-
})
|
|
317
|
-
.finally(done)
|
|
318
|
-
})
|
|
319
|
-
.catch((err) => { throw err })
|
|
320
|
-
})
|
|
321
|
-
it(`should write ${fileCount} files in a new directory`, async () => {
|
|
322
|
-
// return one chunk of random data
|
|
323
|
-
function* dataGenerator() { yield rand(READ_SZ) }
|
|
324
|
-
for (let i = 0; i < fileCount; i++) {
|
|
325
|
-
const bytesWritten = await fixture.api.write(tempFilename(fixture.name, i), dataGenerator())
|
|
326
|
-
expect(bytesWritten).to.equal(READ_SZ, 'expected write API to return correct number of bytes written')
|
|
327
|
-
}
|
|
328
|
-
})
|
|
329
|
-
it('should write a file in a new directory using a stream', async () => {
|
|
330
|
-
// create a random temp file, write it
|
|
331
|
-
const tempFile = `/tmp/${randomstring.generate(10)}_cool_${Date.now()}`
|
|
332
|
-
fs.writeFileSync(tempFile, randomStreamFileData)
|
|
333
|
-
const reader = fs.createReadStream(tempFile)
|
|
334
|
-
const streamFile = fixture.name + '_stream'
|
|
335
|
-
const bytesWritten = await fixture.api.write(streamFile, reader)
|
|
336
|
-
expect(bytesWritten).to.equal(randomStreamFileSize, 'expected write API to return correct number of bytes written for STREAM')
|
|
337
|
-
})
|
|
338
|
-
it("should successfully read the file back that was stream-written", async () => {
|
|
339
|
-
const streamFile = fixture.name + '_stream'
|
|
340
|
-
const singleFile = (await fixture.api.readFile(streamFile))
|
|
341
|
-
expect(singleFile).to.have.lengthOf(randomStreamFileSize)
|
|
342
|
-
for (let i = 0; i < singleFile.length; i++) {
|
|
343
|
-
expect(singleFile[i]).to.equal(randomStreamFileData[i])
|
|
344
|
-
}
|
|
345
|
-
const removal = await fixture.api.remove(streamFile)
|
|
346
|
-
expect(removal).to.equal(streamFile, `expected stream file to be deleted, but was: ${removal}`)
|
|
347
|
-
})
|
|
348
|
-
it("should successfully list a file individually", async () => {
|
|
349
|
-
const singleFile = await fixture.api.list(fixture.name)
|
|
350
|
-
expect(singleFile).to.have.lengthOf(1)
|
|
351
|
-
expect(singleFile[0]).to.have.property('name', fixture.name)
|
|
352
|
-
})
|
|
353
|
-
it("should successfully list files in the base directory", async () => {
|
|
354
|
-
const baseListing = await fixture.api.list()
|
|
355
|
-
expect(baseListing).to.have.lengthOf.greaterThanOrEqual(1)
|
|
356
|
-
expect(baseListing.find(o => o.name === dirname(randomParent) || o.name === dirname(randomParent)+'/')).to.not.be.null
|
|
357
|
-
})
|
|
358
|
-
it("should successfully list files in a subdirectory, with or without a trailing slash", async () => {
|
|
359
|
-
const noSlash = await fixture.api.list(randomParent)
|
|
360
|
-
expect(noSlash).to.have.lengthOf.greaterThanOrEqual(1)
|
|
361
|
-
const withSlash = await fixture.api.list(randomParent+'/')
|
|
362
|
-
expect(withSlash).to.have.lengthOf.greaterThanOrEqual(1)
|
|
363
|
-
for (const f of noSlash) {
|
|
364
|
-
expect(withSlash.find(o => o.name === f.name)).to.not.be.null
|
|
365
|
-
}
|
|
366
|
-
for (const f of withSlash) {
|
|
367
|
-
expect(noSlash.find(o => o.name === f.name)).to.not.be.null
|
|
368
|
-
}
|
|
369
|
-
})
|
|
370
|
-
it("should load metadata for one of the new files", async () => {
|
|
371
|
-
await assertMeta(fixture.api, fixture.name, READ_SZ)
|
|
372
|
-
})
|
|
373
|
-
it("should see correct types on objects returned from a listing of the new directory", async () => {
|
|
374
|
-
const objects = await fixture.api.list(randomParent)
|
|
375
|
-
expect(objects).to.have.lengthOf(1)
|
|
376
|
-
expect(objects[0]).to.have.property('type', M_DIR, `subdir should have type ${M_DIR}`)
|
|
377
|
-
})
|
|
378
|
-
it("should see correct types on objects returned from a listing of the subdirectory", async () => {
|
|
379
|
-
const objects = await fixture.api.list(`${randomParent}/${subdirName}`)
|
|
380
|
-
expect(objects).to.have.lengthOf(fileCount)
|
|
381
|
-
for (let i = 0; i < fileCount; i++) {
|
|
382
|
-
// we should find all the files, and they should all have the correct type
|
|
383
|
-
expect(objects
|
|
384
|
-
.find(o => (o.type === M_FILE && o.name === tempFilename(fixture.name, i)))
|
|
385
|
-
).to.not.be.null
|
|
386
|
-
}
|
|
387
|
-
})
|
|
388
|
-
it(`should mirror its subdirectory (${driverName}/${randomParent}) to another place (${mirrorDriver}/${mirrorDest})`, async () => {
|
|
389
|
-
const results = await fixture.mirrorApi.mirror(fixture.api, mirrorDest, randomParent)
|
|
390
|
-
expect(results).to.have.property('errors', 0, 'expected no errors in mirroring')
|
|
391
|
-
expect(results).to.have.property('success').greaterThan(0, 'expected some successes in mirroring')
|
|
392
|
-
})
|
|
393
|
-
it("should see the same files mirrored both places", async () => {
|
|
394
|
-
const originalThings = await fixture.api.list(fullSubdirPath)
|
|
395
|
-
const mirrorPath = `${mirrorDest}${subdirName}`
|
|
396
|
-
const mirrorThings = await fixture.mirrorApi.list(mirrorPath)
|
|
397
|
-
expect(originalThings.length === mirrorThings.length).to.be.true
|
|
398
|
-
|
|
399
|
-
const intersection = originalThings
|
|
400
|
-
.filter(orig => mirrorThings
|
|
401
|
-
.find(m => basename(m.name) === basename(orig.name)))
|
|
402
|
-
expect(intersection.length === originalThings.length).to.be.true
|
|
403
|
-
})
|
|
404
|
-
it("loading metadata on a mirrored file succeeds", async () => {
|
|
405
|
-
const destPath = mirrorDest + subdirName + '/' + basename(fixture.name)
|
|
406
|
-
await assertMeta(fixture.mirrorApi, destPath, READ_SZ)
|
|
407
|
-
})
|
|
408
|
-
it("should recursively delete the mirrored data", async () => {
|
|
409
|
-
const recursive = true
|
|
410
|
-
const removed = await fixture.mirrorApi.remove(mirrorDest, {recursive})
|
|
411
|
-
expect(!!removed).to.be.true
|
|
412
|
-
})
|
|
413
|
-
it("should recursively delete the directory and file we just created", async () => {
|
|
414
|
-
const recursive = true
|
|
415
|
-
const removed = await fixture.api.remove(randomParent, {recursive})
|
|
416
|
-
expect(!!removed).to.be.true
|
|
417
|
-
})
|
|
418
|
-
it("loading metadata on the file we wrote now fails", async () => {
|
|
419
|
-
await assertMetaFail(fixture.api, fixture.name)
|
|
420
|
-
})
|
|
421
|
-
it("loading metadata on a mirrored file now fails", async () => {
|
|
422
|
-
const destPath = mirrorDest + subdirName + '/' + basename(fixture.name)
|
|
423
|
-
await assertMetaFail(fixture.mirrorApi, destPath)
|
|
424
|
-
})
|
|
425
|
-
it("loading metadata on the parent dir we wrote now fails", async () => {
|
|
426
|
-
await assertMetaFail(fixture.api, randomParent)
|
|
427
|
-
})
|
|
434
|
+
it("loading metadata on a mirrored file now fails", async () => {
|
|
435
|
+
const destPath = mirrorDest + subdirName + '/' + basename(fixture.name)
|
|
436
|
+
await assertMetaFail(fixture.mirrorApi, destPath)
|
|
428
437
|
})
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
describe(`${driverTest} - expect MobilettoNotFoundError when reading nonexistent file `, () => {
|
|
432
|
-
it("should throw MobilettoNotFoundError when trying to read a file that does not exist", async () => {
|
|
433
|
-
const api = await mobiletto(driverName, config.key, config.secret, config.opts)
|
|
434
|
-
try {
|
|
435
|
-
await api.read(nonexistentFile, () => {
|
|
436
|
-
assert.fail(`ERROR: reading non-existent file should NOT succeed`)
|
|
437
|
-
})
|
|
438
|
-
} catch (err) {
|
|
439
|
-
expect(err).to.be.instanceof(MobilettoNotFoundError, `expected MobilettoNotFoundError, got: ${err}`)
|
|
440
|
-
}
|
|
438
|
+
it("loading metadata on the parent dir we wrote now fails", async () => {
|
|
439
|
+
await assertMetaFail(fixture.api, randomParent)
|
|
441
440
|
})
|
|
442
441
|
})
|
|
442
|
+
}
|
|
443
443
|
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
assert.fail(`ERROR: reading
|
|
450
|
-
}
|
|
451
|
-
|
|
452
|
-
}
|
|
453
|
-
}
|
|
444
|
+
describe(`${driverTest} - expect MobilettoNotFoundError when reading nonexistent file `, () => {
|
|
445
|
+
it("should throw MobilettoNotFoundError when trying to read a file that does not exist", async () => {
|
|
446
|
+
const api = await mobiletto(driverName, config.key, config.secret, config.opts)
|
|
447
|
+
try {
|
|
448
|
+
await api.read(nonexistentFile, () => {
|
|
449
|
+
assert.fail(`ERROR: reading non-existent file should NOT succeed`)
|
|
450
|
+
})
|
|
451
|
+
} catch (err) {
|
|
452
|
+
expect(err).to.be.instanceof(MobilettoNotFoundError, `expected MobilettoNotFoundError, got: ${err}`)
|
|
453
|
+
}
|
|
454
454
|
})
|
|
455
|
+
})
|
|
455
456
|
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
}
|
|
466
|
-
})
|
|
457
|
+
describe(`${driverTest} - expect MobilettoNotFoundError when reading metadata for nonexistent file`, () => {
|
|
458
|
+
it("should throw MobilettoNotFoundError when trying to read metadata for a file that does not exist", async () => {
|
|
459
|
+
const api = await mobiletto(driverName, config.key, config.secret, config.opts)
|
|
460
|
+
try {
|
|
461
|
+
const meta = await api.metadata(nonexistentFile)
|
|
462
|
+
assert.fail(`ERROR: reading metadata for non-existent file should NOT succeed, but it returned ${meta ? JSON.stringify(meta) : 'null or undefined'}`)
|
|
463
|
+
} catch (err) {
|
|
464
|
+
expect(err).to.be.instanceof(MobilettoNotFoundError, `expected MobilettoNotFoundError, got: ${err}`)
|
|
465
|
+
}
|
|
467
466
|
})
|
|
467
|
+
})
|
|
468
468
|
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
469
|
+
describe(`${driverTest} - expect MobilettoNotFoundError when removing non-existent file`, () => {
|
|
470
|
+
it("should throw MobilettoNotFoundError when trying to remove a file that does not exist", async () => {
|
|
471
|
+
const api = await mobiletto(driverName, config.key, config.secret, config.opts)
|
|
472
|
+
try {
|
|
473
|
+
if (await api.remove(nonexistentFile)) {
|
|
474
|
+
assert.fail('ERROR: removing non-existent file should NOT succeed')
|
|
474
475
|
}
|
|
475
|
-
})
|
|
476
|
+
} catch (err) {
|
|
477
|
+
expect(err).to.be.instanceof(MobilettoNotFoundError, `expected MobilettoNotFoundError, got: ${err}`)
|
|
478
|
+
}
|
|
476
479
|
})
|
|
480
|
+
})
|
|
477
481
|
|
|
482
|
+
describe(`${driverTest} - quietly removing non-existent file does not throw MobilettoNotFoundError`, () => {
|
|
483
|
+
it("should NOT throw MobilettoNotFoundError when quietly removing a file that does not exist", async () => {
|
|
484
|
+
const api = await mobiletto(driverName, config.key, config.secret, config.opts)
|
|
485
|
+
if (!(await api.remove(nonexistentFile, {quiet: true}))) {
|
|
486
|
+
assert.fail('ERROR: quietly removing non-existent file should still return true')
|
|
487
|
+
}
|
|
488
|
+
})
|
|
478
489
|
})
|
|
490
|
+
|
|
491
|
+
})
|
|
479
492
|
}
|
|
480
493
|
}
|
|
481
494
|
|
package/util/logger.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
const winston = require('winston')
|
|
2
2
|
|
|
3
3
|
const logger = winston.createLogger({
|
|
4
|
-
level: process.env.MOBILETTO_LOG_LEVEL || '
|
|
4
|
+
level: process.env.MOBILETTO_LOG_LEVEL || 'error',
|
|
5
5
|
format: winston.format.simple(),
|
|
6
6
|
transports: process.env.MOBILETTO_LOG_FILE
|
|
7
7
|
? [ new winston.transports.File({ filename: process.env.MOBILETTO_LOG_FILE }) ]
|