mobiletto 1.1.9 → 1.1.12
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 +82 -4
- package/docs/README.md +113 -0
- package/docs/af/README.md +481 -0
- package/docs/am/README.md +481 -0
- package/docs/ar/README.md +481 -0
- package/docs/az/README.md +481 -0
- package/docs/be/README.md +481 -0
- package/docs/bg/README.md +481 -0
- package/docs/bn/README.md +481 -0
- package/docs/bs/README.md +481 -0
- package/docs/ca/README.md +481 -0
- package/docs/ceb/README.md +481 -0
- package/docs/co/README.md +481 -0
- package/docs/cs/README.md +481 -0
- package/docs/cy/README.md +481 -0
- package/docs/da/README.md +481 -0
- package/docs/de/README.md +481 -0
- package/docs/el/README.md +481 -0
- package/docs/eo/README.md +481 -0
- package/docs/es/README.md +481 -0
- package/docs/et/README.md +481 -0
- package/docs/eu/README.md +481 -0
- package/docs/fa/README.md +481 -0
- package/docs/fi/README.md +481 -0
- package/docs/fr/README.md +481 -0
- package/docs/fy/README.md +481 -0
- package/docs/ga/README.md +481 -0
- package/docs/gd/README.md +481 -0
- package/docs/gl/README.md +481 -0
- package/docs/gu/README.md +481 -0
- package/docs/ha/README.md +481 -0
- package/docs/haw/README.md +481 -0
- package/docs/he/README.md +481 -0
- package/docs/hi/README.md +481 -0
- package/docs/hmn/README.md +481 -0
- package/docs/hr/README.md +481 -0
- package/docs/ht/README.md +481 -0
- package/docs/hu/README.md +481 -0
- package/docs/hy/README.md +481 -0
- package/docs/id/README.md +481 -0
- package/docs/ig/README.md +481 -0
- package/docs/is/README.md +481 -0
- package/docs/it/README.md +481 -0
- package/docs/iw/README.md +481 -0
- package/docs/ja/README.md +481 -0
- package/docs/jv/README.md +481 -0
- package/docs/ka/README.md +481 -0
- package/docs/kk/README.md +481 -0
- package/docs/km/README.md +481 -0
- package/docs/kn/README.md +481 -0
- package/docs/ko/README.md +481 -0
- package/docs/ku/README.md +481 -0
- package/docs/ky/README.md +481 -0
- package/docs/la/README.md +481 -0
- package/docs/lb/README.md +481 -0
- package/docs/lo/README.md +481 -0
- package/docs/lt/README.md +481 -0
- package/docs/lv/README.md +481 -0
- package/docs/mg/README.md +481 -0
- package/docs/mi/README.md +481 -0
- package/docs/mk/README.md +481 -0
- package/docs/ml/README.md +481 -0
- package/docs/mn/README.md +481 -0
- package/docs/mr/README.md +481 -0
- package/docs/ms/README.md +481 -0
- package/docs/mt/README.md +481 -0
- package/docs/my/README.md +481 -0
- package/docs/ne/README.md +481 -0
- package/docs/nl/README.md +481 -0
- package/docs/no/README.md +481 -0
- package/docs/ny/README.md +481 -0
- package/docs/or/README.md +481 -0
- package/docs/pa/README.md +481 -0
- package/docs/pl/README.md +481 -0
- package/docs/ps/README.md +481 -0
- package/docs/pt/README.md +481 -0
- package/docs/ro/README.md +481 -0
- package/docs/ru/README.md +481 -0
- package/docs/rw/README.md +481 -0
- package/docs/sd/README.md +481 -0
- package/docs/si/README.md +481 -0
- package/docs/sk/README.md +481 -0
- package/docs/sl/README.md +481 -0
- package/docs/sm/README.md +481 -0
- package/docs/sn/README.md +481 -0
- package/docs/so/README.md +481 -0
- package/docs/sq/README.md +481 -0
- package/docs/sr/README.md +481 -0
- package/docs/st/README.md +481 -0
- package/docs/su/README.md +481 -0
- package/docs/sv/README.md +481 -0
- package/docs/sw/README.md +481 -0
- package/docs/ta/README.md +481 -0
- package/docs/te/README.md +481 -0
- package/docs/tg/README.md +481 -0
- package/docs/th/README.md +481 -0
- package/docs/tk/README.md +481 -0
- package/docs/tl/README.md +481 -0
- package/docs/tr/README.md +481 -0
- package/docs/tt/README.md +481 -0
- package/docs/ug/README.md +481 -0
- package/docs/uk/README.md +481 -0
- package/docs/ur/README.md +481 -0
- package/docs/uz/README.md +481 -0
- package/docs/vi/README.md +481 -0
- package/docs/xh/README.md +481 -0
- package/docs/yi/README.md +481 -0
- package/docs/yo/README.md +481 -0
- package/docs/zh/README.md +481 -0
- package/docs/zu/README.md +481 -0
- package/drivers/b2/index.js +24 -6
- package/hokey.json +16 -0
- package/index.js +32 -16
- package/package.json +3 -2
- package/test/api.spec.js +319 -306
- package/util/logger.js +1 -1
- package/util/redis.js +1 -1
package/test/api.spec.js
CHANGED
|
@@ -125,360 +125,373 @@ const redisTests = () => [REDIS_ENABLED, REDIS_DISABLED]
|
|
|
125
125
|
// const redisTests = () => [REDIS_DISABLED]
|
|
126
126
|
|
|
127
127
|
for (const redisSetup of redisTests()) {
|
|
128
|
-
|
|
128
|
+
if (!redisSetup.enabled) continue
|
|
129
129
|
|
|
130
130
|
for (const driverName of DRIVER_NAMES) {
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
131
|
+
// For testing single drivers
|
|
132
|
+
// if (driverName !== 'b2') 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
|
+
}
|
|
147
158
|
})
|
|
159
|
+
})
|
|
148
160
|
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
} catch (e) {
|
|
155
|
-
logger.error(`error creating API: ${e} ${JSON.stringify(e)}`)
|
|
156
|
-
throw e
|
|
157
|
-
}
|
|
158
|
-
})
|
|
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')
|
|
159
166
|
})
|
|
167
|
+
})
|
|
160
168
|
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
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)
|
|
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
|
|
167
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
|
+
})
|
|
168
204
|
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
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
|
|
172
211
|
const randomData = rand(size)
|
|
173
212
|
const fileSuffix = '' + Date.now()
|
|
174
213
|
let fixture
|
|
175
214
|
before((done) => {
|
|
176
215
|
const name = `test_file_${fileSuffix}`
|
|
177
|
-
|
|
216
|
+
const opts = Object.assign({}, config.opts, {readOnly: true})
|
|
217
|
+
connect(driverName, config.key, config.secret, opts, encryption)
|
|
178
218
|
.then(api => { fixture = {api, name, randomData} })
|
|
219
|
+
.catch(err => { throw err })
|
|
179
220
|
.finally(done)
|
|
180
221
|
})
|
|
181
|
-
it("should write a file", async () => {
|
|
222
|
+
it("should try to write a file and fail", async () => {
|
|
182
223
|
const response = await writeRandomFile(fixture, size)
|
|
183
|
-
expect(response).to.
|
|
224
|
+
expect(response).to.be.false
|
|
184
225
|
})
|
|
185
|
-
it("should read the file we
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
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
|
+
}
|
|
189
235
|
})
|
|
190
|
-
it("should load metadata on the file we
|
|
191
|
-
|
|
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
|
+
}
|
|
192
245
|
})
|
|
193
|
-
it("should delete the file we
|
|
246
|
+
it("should fail to delete the file we did not write", async () => {
|
|
194
247
|
const removed = await fixture.api.remove(fixture.name)
|
|
195
|
-
expect(!!removed).to.be.
|
|
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)
|
|
248
|
+
expect(!!removed).to.be.false
|
|
202
249
|
})
|
|
203
250
|
})
|
|
251
|
+
}
|
|
204
252
|
|
|
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
|
-
|
|
237
|
-
|
|
238
|
-
|
|
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
|
-
}
|
|
245
|
-
})
|
|
246
|
-
it("should fail to delete the file we did not write", async () => {
|
|
247
|
-
const removed = await fixture.api.remove(fixture.name)
|
|
248
|
-
expect(!!removed).to.be.false
|
|
249
|
-
})
|
|
250
|
-
})
|
|
251
|
-
}
|
|
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
|
+
})
|
|
252
287
|
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
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
|
|
259
308
|
let fixture
|
|
260
309
|
before((done) => {
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
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
|
+
})
|
|
264
323
|
.catch((err) => { throw err })
|
|
265
|
-
.finally(done)
|
|
266
324
|
})
|
|
267
|
-
it(
|
|
268
|
-
|
|
269
|
-
|
|
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
|
+
}
|
|
270
332
|
})
|
|
271
|
-
it(
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
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')
|
|
275
341
|
})
|
|
276
|
-
it("should
|
|
277
|
-
|
|
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}`)
|
|
278
351
|
})
|
|
279
|
-
it("should
|
|
280
|
-
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.greaterThanOrEqual(fileCount)
|
|
377
|
+
// Not all drivers return "dir" entries when recursively listing. We should see all the files though
|
|
378
|
+
// expect(allFiles.find(f => f.name === fullSubdirPath && f.type === M_DIR)).to.not.be.null
|
|
379
|
+
expect(allFiles.find(f => f.name === fixture.name && f.type === M_FILE)).to.not.be.null
|
|
380
|
+
for (let i = 0; i < fileCount; i++) {
|
|
381
|
+
expect(allFiles.find(f => f.name === tempFilename(fixture.name, i) && f.type === M_FILE)).to.not.be.null
|
|
382
|
+
}
|
|
383
|
+
})
|
|
384
|
+
it("should load metadata for one of the new files", async () => {
|
|
385
|
+
await assertMeta(fixture.api, fixture.name, READ_SZ)
|
|
386
|
+
})
|
|
387
|
+
it("should see correct types on objects returned from a listing of the new directory", async () => {
|
|
388
|
+
const objects = await fixture.api.list(randomParent)
|
|
389
|
+
expect(objects).to.have.lengthOf(1)
|
|
390
|
+
expect(objects[0]).to.have.property('type', M_DIR, `subdir should have type ${M_DIR}`)
|
|
391
|
+
})
|
|
392
|
+
it("should see correct types on objects returned from a listing of the subdirectory", async () => {
|
|
393
|
+
const objects = await fixture.api.list(`${randomParent}/${subdirName}/`)
|
|
394
|
+
expect(objects).to.have.lengthOf(fileCount)
|
|
395
|
+
for (let i = 0; i < fileCount; i++) {
|
|
396
|
+
// we should find all the files, and they should all have the correct type
|
|
397
|
+
expect(objects
|
|
398
|
+
.find(o => (o.type === M_FILE && o.name === tempFilename(fixture.name, i)))
|
|
399
|
+
).to.not.be.null
|
|
400
|
+
}
|
|
401
|
+
})
|
|
402
|
+
it(`should mirror its subdirectory (${driverName}/${randomParent}) to another place (${mirrorDriver}/${mirrorDest})`, async () => {
|
|
403
|
+
const results = await fixture.mirrorApi.mirror(fixture.api, mirrorDest, randomParent)
|
|
404
|
+
expect(results).to.have.property('errors', 0, 'expected no errors in mirroring')
|
|
405
|
+
expect(results).to.have.property('success').greaterThan(0, 'expected some successes in mirroring')
|
|
406
|
+
})
|
|
407
|
+
it("should see the same files mirrored both places", async () => {
|
|
408
|
+
const originalThings = await fixture.api.list(fullSubdirPath, { recursive: true })
|
|
409
|
+
const mirrorPath = `${mirrorDest}${subdirName}`
|
|
410
|
+
const mirrorThings = await fixture.mirrorApi.list(mirrorPath, { recursive: true })
|
|
411
|
+
expect(originalThings.length === mirrorThings.length).to.be.true
|
|
412
|
+
|
|
413
|
+
const originalFiles = originalThings.filter(o => o.type === M_FILE)
|
|
414
|
+
const mirrorFiles = mirrorThings.filter(o => o.type === M_FILE)
|
|
415
|
+
const intersection = originalFiles
|
|
416
|
+
.filter(orig => mirrorFiles
|
|
417
|
+
.find(m => basename(m.name) === basename(orig.name)))
|
|
418
|
+
expect(intersection.length === originalFiles.length).to.be.true
|
|
419
|
+
})
|
|
420
|
+
it("loading metadata on a mirrored file succeeds", async () => {
|
|
421
|
+
const destPath = mirrorDest + subdirName + '/' + basename(fixture.name)
|
|
422
|
+
await assertMeta(fixture.mirrorApi, destPath, READ_SZ)
|
|
423
|
+
})
|
|
424
|
+
it("should recursively delete the mirrored data", async () => {
|
|
425
|
+
const recursive = true
|
|
426
|
+
const removed = await fixture.mirrorApi.remove(mirrorDest, {recursive})
|
|
427
|
+
expect(!!removed).to.be.true
|
|
428
|
+
})
|
|
429
|
+
it("should recursively delete the directory and file we just created", async () => {
|
|
430
|
+
const recursive = true
|
|
431
|
+
const removed = await fixture.api.remove(randomParent, {recursive})
|
|
281
432
|
expect(!!removed).to.be.true
|
|
282
433
|
})
|
|
283
|
-
it("loading metadata on the
|
|
434
|
+
it("loading metadata on the file we wrote now fails", async () => {
|
|
284
435
|
await assertMetaFail(fixture.api, fixture.name)
|
|
285
436
|
})
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
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
|
-
// describe(`${driverTest} - ENCRYPTION write files in a new dir, read metadata, recursively delete`, () => {
|
|
296
|
-
// const encryption = {key: rand(32)}
|
|
297
|
-
// const encryption = null
|
|
298
|
-
// a random directory and file within it
|
|
299
|
-
const randomParent = `testRPD_${rand(2)}/rand_${rand(4)}`
|
|
300
|
-
const subdirName = `subdir_` + Date.now()
|
|
301
|
-
const fullSubdirPath = `${randomParent}/${subdirName}`
|
|
302
|
-
const randomPath = `${fullSubdirPath}/random_file_${Date.now()}`
|
|
303
|
-
const randomStreamFileSize = READ_SZ * 10
|
|
304
|
-
const randomStreamFileData = crypto.randomBytes(randomStreamFileSize)
|
|
305
|
-
//const fileCount = 3 + Math.floor(Math.random() * 10)
|
|
306
|
-
const fileCount = 2
|
|
307
|
-
let fixture
|
|
308
|
-
before((done) => {
|
|
309
|
-
mobiletto(driverName, config.key, config.secret, config.opts, encryption)
|
|
310
|
-
.then(api => {
|
|
311
|
-
// const mirrorEnc = { key: rand(32) }
|
|
312
|
-
const mirrorEnc = null
|
|
313
|
-
mobiletto(mirrorDriver, mirrorConfig.key, mirrorConfig.secret, mirrorConfig.opts, mirrorEnc)
|
|
314
|
-
.then(mirrorApi => {
|
|
315
|
-
fixture = {api, mirrorApi, name: randomPath}
|
|
316
|
-
})
|
|
317
|
-
.catch((err) => {
|
|
318
|
-
throw err
|
|
319
|
-
})
|
|
320
|
-
.finally(done)
|
|
321
|
-
})
|
|
322
|
-
.catch((err) => { throw err })
|
|
323
|
-
})
|
|
324
|
-
it(`should write ${fileCount} files in a new directory`, async () => {
|
|
325
|
-
// return one chunk of random data
|
|
326
|
-
function* dataGenerator() { yield rand(READ_SZ) }
|
|
327
|
-
for (let i = 0; i < fileCount; i++) {
|
|
328
|
-
const bytesWritten = await fixture.api.write(tempFilename(fixture.name, i), dataGenerator())
|
|
329
|
-
expect(bytesWritten).to.equal(READ_SZ, 'expected write API to return correct number of bytes written')
|
|
330
|
-
}
|
|
331
|
-
})
|
|
332
|
-
it('should write a file in a new directory using a stream', async () => {
|
|
333
|
-
// create a random temp file, write it
|
|
334
|
-
const tempFile = `/tmp/${randomstring.generate(10)}_cool_${Date.now()}`
|
|
335
|
-
fs.writeFileSync(tempFile, randomStreamFileData)
|
|
336
|
-
const reader = fs.createReadStream(tempFile)
|
|
337
|
-
const streamFile = fixture.name + '_stream'
|
|
338
|
-
const bytesWritten = await fixture.api.write(streamFile, reader)
|
|
339
|
-
expect(bytesWritten).to.equal(randomStreamFileSize, 'expected write API to return correct number of bytes written for STREAM')
|
|
340
|
-
})
|
|
341
|
-
it("should successfully read the file back that was stream-written", async () => {
|
|
342
|
-
const streamFile = fixture.name + '_stream'
|
|
343
|
-
const singleFile = (await fixture.api.readFile(streamFile))
|
|
344
|
-
expect(singleFile).to.have.lengthOf(randomStreamFileSize)
|
|
345
|
-
for (let i = 0; i < singleFile.length; i++) {
|
|
346
|
-
expect(singleFile[i]).to.equal(randomStreamFileData[i])
|
|
347
|
-
}
|
|
348
|
-
const removal = await fixture.api.remove(streamFile)
|
|
349
|
-
expect(removal).to.equal(streamFile, `expected stream file to be deleted, but was: ${removal}`)
|
|
350
|
-
})
|
|
351
|
-
it("should successfully list a file individually", async () => {
|
|
352
|
-
const singleFile = await fixture.api.list(fixture.name)
|
|
353
|
-
expect(singleFile).to.have.lengthOf(1)
|
|
354
|
-
expect(singleFile[0]).to.have.property('name', fixture.name)
|
|
355
|
-
})
|
|
356
|
-
it("should successfully list files in the base directory", async () => {
|
|
357
|
-
const baseListing = await fixture.api.list()
|
|
358
|
-
expect(baseListing).to.have.lengthOf.greaterThanOrEqual(1)
|
|
359
|
-
expect(baseListing.find(o => o.name === dirname(randomParent) || o.name === dirname(randomParent)+'/')).to.not.be.null
|
|
360
|
-
})
|
|
361
|
-
it("should successfully list files in a subdirectory, with or without a trailing slash", async () => {
|
|
362
|
-
const noSlash = await fixture.api.list(randomParent)
|
|
363
|
-
expect(noSlash).to.have.lengthOf.greaterThanOrEqual(1)
|
|
364
|
-
const withSlash = await fixture.api.list(randomParent+'/')
|
|
365
|
-
expect(withSlash).to.have.lengthOf.greaterThanOrEqual(1)
|
|
366
|
-
for (const f of noSlash) {
|
|
367
|
-
expect(withSlash.find(o => o.name === f.name)).to.not.be.null
|
|
368
|
-
}
|
|
369
|
-
for (const f of withSlash) {
|
|
370
|
-
expect(noSlash.find(o => o.name === f.name)).to.not.be.null
|
|
371
|
-
}
|
|
372
|
-
})
|
|
373
|
-
it("should load metadata for one of the new files", async () => {
|
|
374
|
-
await assertMeta(fixture.api, fixture.name, READ_SZ)
|
|
375
|
-
})
|
|
376
|
-
it("should see correct types on objects returned from a listing of the new directory", async () => {
|
|
377
|
-
const objects = await fixture.api.list(randomParent)
|
|
378
|
-
expect(objects).to.have.lengthOf(1)
|
|
379
|
-
expect(objects[0]).to.have.property('type', M_DIR, `subdir should have type ${M_DIR}`)
|
|
380
|
-
})
|
|
381
|
-
it("should see correct types on objects returned from a listing of the subdirectory", async () => {
|
|
382
|
-
const objects = await fixture.api.list(`${randomParent}/${subdirName}`)
|
|
383
|
-
expect(objects).to.have.lengthOf(fileCount)
|
|
384
|
-
for (let i = 0; i < fileCount; i++) {
|
|
385
|
-
// we should find all the files, and they should all have the correct type
|
|
386
|
-
expect(objects
|
|
387
|
-
.find(o => (o.type === M_FILE && o.name === tempFilename(fixture.name, i)))
|
|
388
|
-
).to.not.be.null
|
|
389
|
-
}
|
|
390
|
-
})
|
|
391
|
-
it(`should mirror its subdirectory (${driverName}/${randomParent}) to another place (${mirrorDriver}/${mirrorDest})`, async () => {
|
|
392
|
-
const results = await fixture.mirrorApi.mirror(fixture.api, mirrorDest, randomParent)
|
|
393
|
-
expect(results).to.have.property('errors', 0, 'expected no errors in mirroring')
|
|
394
|
-
expect(results).to.have.property('success').greaterThan(0, 'expected some successes in mirroring')
|
|
395
|
-
})
|
|
396
|
-
it("should see the same files mirrored both places", async () => {
|
|
397
|
-
const originalThings = await fixture.api.list(fullSubdirPath)
|
|
398
|
-
const mirrorPath = `${mirrorDest}${subdirName}`
|
|
399
|
-
const mirrorThings = await fixture.mirrorApi.list(mirrorPath)
|
|
400
|
-
expect(originalThings.length === mirrorThings.length).to.be.true
|
|
401
|
-
|
|
402
|
-
const intersection = originalThings
|
|
403
|
-
.filter(orig => mirrorThings
|
|
404
|
-
.find(m => basename(m.name) === basename(orig.name)))
|
|
405
|
-
expect(intersection.length === originalThings.length).to.be.true
|
|
406
|
-
})
|
|
407
|
-
it("loading metadata on a mirrored file succeeds", async () => {
|
|
408
|
-
const destPath = mirrorDest + subdirName + '/' + basename(fixture.name)
|
|
409
|
-
await assertMeta(fixture.mirrorApi, destPath, READ_SZ)
|
|
410
|
-
})
|
|
411
|
-
it("should recursively delete the mirrored data", async () => {
|
|
412
|
-
const recursive = true
|
|
413
|
-
const removed = await fixture.mirrorApi.remove(mirrorDest, {recursive})
|
|
414
|
-
expect(!!removed).to.be.true
|
|
415
|
-
})
|
|
416
|
-
it("should recursively delete the directory and file we just created", async () => {
|
|
417
|
-
const recursive = true
|
|
418
|
-
const removed = await fixture.api.remove(randomParent, {recursive})
|
|
419
|
-
expect(!!removed).to.be.true
|
|
420
|
-
})
|
|
421
|
-
it("loading metadata on the file we wrote now fails", async () => {
|
|
422
|
-
await assertMetaFail(fixture.api, fixture.name)
|
|
423
|
-
})
|
|
424
|
-
it("loading metadata on a mirrored file now fails", async () => {
|
|
425
|
-
const destPath = mirrorDest + subdirName + '/' + basename(fixture.name)
|
|
426
|
-
await assertMetaFail(fixture.mirrorApi, destPath)
|
|
427
|
-
})
|
|
428
|
-
it("loading metadata on the parent dir we wrote now fails", async () => {
|
|
429
|
-
await assertMetaFail(fixture.api, randomParent)
|
|
430
|
-
})
|
|
437
|
+
it("loading metadata on a mirrored file now fails", async () => {
|
|
438
|
+
const destPath = mirrorDest + subdirName + '/' + basename(fixture.name)
|
|
439
|
+
await assertMetaFail(fixture.mirrorApi, destPath)
|
|
431
440
|
})
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
describe(`${driverTest} - expect MobilettoNotFoundError when reading nonexistent file `, () => {
|
|
435
|
-
it("should throw MobilettoNotFoundError when trying to read a file that does not exist", async () => {
|
|
436
|
-
const api = await mobiletto(driverName, config.key, config.secret, config.opts)
|
|
437
|
-
try {
|
|
438
|
-
await api.read(nonexistentFile, () => {
|
|
439
|
-
assert.fail(`ERROR: reading non-existent file should NOT succeed`)
|
|
440
|
-
})
|
|
441
|
-
} catch (err) {
|
|
442
|
-
expect(err).to.be.instanceof(MobilettoNotFoundError, `expected MobilettoNotFoundError, got: ${err}`)
|
|
443
|
-
}
|
|
441
|
+
it("loading metadata on the parent dir we wrote now fails", async () => {
|
|
442
|
+
await assertMetaFail(fixture.api, randomParent)
|
|
444
443
|
})
|
|
445
444
|
})
|
|
445
|
+
}
|
|
446
446
|
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
assert.fail(`ERROR: reading
|
|
453
|
-
}
|
|
454
|
-
|
|
455
|
-
}
|
|
456
|
-
}
|
|
447
|
+
describe(`${driverTest} - expect MobilettoNotFoundError when reading nonexistent file `, () => {
|
|
448
|
+
it("should throw MobilettoNotFoundError when trying to read a file that does not exist", async () => {
|
|
449
|
+
const api = await mobiletto(driverName, config.key, config.secret, config.opts)
|
|
450
|
+
try {
|
|
451
|
+
await api.read(nonexistentFile, () => {
|
|
452
|
+
assert.fail(`ERROR: reading non-existent file should NOT succeed`)
|
|
453
|
+
})
|
|
454
|
+
} catch (err) {
|
|
455
|
+
expect(err).to.be.instanceof(MobilettoNotFoundError, `expected MobilettoNotFoundError, got: ${err}`)
|
|
456
|
+
}
|
|
457
457
|
})
|
|
458
|
+
})
|
|
458
459
|
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
}
|
|
469
|
-
})
|
|
460
|
+
describe(`${driverTest} - expect MobilettoNotFoundError when reading metadata for nonexistent file`, () => {
|
|
461
|
+
it("should throw MobilettoNotFoundError when trying to read metadata for a file that does not exist", async () => {
|
|
462
|
+
const api = await mobiletto(driverName, config.key, config.secret, config.opts)
|
|
463
|
+
try {
|
|
464
|
+
const meta = await api.metadata(nonexistentFile)
|
|
465
|
+
assert.fail(`ERROR: reading metadata for non-existent file should NOT succeed, but it returned ${meta ? JSON.stringify(meta) : 'null or undefined'}`)
|
|
466
|
+
} catch (err) {
|
|
467
|
+
expect(err).to.be.instanceof(MobilettoNotFoundError, `expected MobilettoNotFoundError, got: ${err}`)
|
|
468
|
+
}
|
|
470
469
|
})
|
|
470
|
+
})
|
|
471
471
|
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
472
|
+
describe(`${driverTest} - expect MobilettoNotFoundError when removing non-existent file`, () => {
|
|
473
|
+
it("should throw MobilettoNotFoundError when trying to remove a file that does not exist", async () => {
|
|
474
|
+
const api = await mobiletto(driverName, config.key, config.secret, config.opts)
|
|
475
|
+
try {
|
|
476
|
+
if (await api.remove(nonexistentFile)) {
|
|
477
|
+
assert.fail('ERROR: removing non-existent file should NOT succeed')
|
|
477
478
|
}
|
|
478
|
-
})
|
|
479
|
+
} catch (err) {
|
|
480
|
+
expect(err).to.be.instanceof(MobilettoNotFoundError, `expected MobilettoNotFoundError, got: ${err}`)
|
|
481
|
+
}
|
|
479
482
|
})
|
|
483
|
+
})
|
|
480
484
|
|
|
485
|
+
describe(`${driverTest} - quietly removing non-existent file does not throw MobilettoNotFoundError`, () => {
|
|
486
|
+
it("should NOT throw MobilettoNotFoundError when quietly removing a file that does not exist", async () => {
|
|
487
|
+
const api = await mobiletto(driverName, config.key, config.secret, config.opts)
|
|
488
|
+
if (!(await api.remove(nonexistentFile, {quiet: true}))) {
|
|
489
|
+
assert.fail('ERROR: quietly removing non-existent file should still return true')
|
|
490
|
+
}
|
|
491
|
+
})
|
|
481
492
|
})
|
|
493
|
+
|
|
494
|
+
})
|
|
482
495
|
}
|
|
483
496
|
}
|
|
484
497
|
|