Skip to content

Commit

Permalink
fix downloadBuffer and standard formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
transitive-bullshit committed Sep 15, 2019
1 parent 84b925b commit 33eb1f7
Show file tree
Hide file tree
Showing 13 changed files with 719 additions and 534 deletions.
2 changes: 1 addition & 1 deletion index.js
Expand Up @@ -13,7 +13,7 @@ function defaults (defaultOptions = { }) {
}
}

for (let method in methods) {
for (const method in methods) {
const impl = methods[method]
storage[method] = (...args) => {
const resolvedArgs = args.map(opts => {
Expand Down
2 changes: 1 addition & 1 deletion lib/methods/content-length.js
Expand Up @@ -6,7 +6,7 @@ module.exports = async function contentLength (opts) {
assertParam(opts, 'file')
const { file } = opts

const [ metadata ] = await file.getMetadata().catch((err) => {
const [metadata] = await file.getMetadata().catch((err) => {
if (err.code === 404) return [{ size: 0 }]
throw err
})
Expand Down
2 changes: 1 addition & 1 deletion lib/methods/copy-file.test.js
Expand Up @@ -22,6 +22,6 @@ describe('copy-file', () => {
.file('test-key-1')

await copyFile({ file: sourceFile }, { file: destFile })
assert.deepEqual(sourceFile.copy.args[0], [ destFile ])
assert.deepEqual(sourceFile.copy.args[0], [destFile])
})
})
3 changes: 2 additions & 1 deletion lib/methods/download-buffer.js
Expand Up @@ -6,5 +6,6 @@ module.exports = async function downloadBuffer (opts) {
assertParam(opts, 'file')
const { file } = opts

return file.download()
const result = await file.download()
return result[0]
}
4 changes: 2 additions & 2 deletions lib/methods/download-buffer.test.js
Expand Up @@ -17,7 +17,7 @@ describe('download-buffer', () => {
.bucket('test-bucket-0')
.file('test-key-0')

assert.deepEqual(await downloadBuffer({ file }), 'download')
assert.deepEqual(file.download.args[0], [ ])
assert.deepEqual(await downloadBuffer({ file }), ['download'])
assert.deepEqual(file.download.args[0], [])
})
})
2 changes: 1 addition & 1 deletion lib/methods/download-file.test.js
Expand Up @@ -18,6 +18,6 @@ describe('download-file', () => {
.file('test-key-0')

assert.deepEqual(await downloadFile({ file, localPath: 'test-local-path' }), 'download')
assert.deepEqual(file.download.args[0], [ { destination: 'test-local-path' } ])
assert.deepEqual(file.download.args[0], [{ destination: 'test-local-path' }])
})
})
2 changes: 1 addition & 1 deletion lib/methods/download-stream.test.js
Expand Up @@ -18,6 +18,6 @@ describe('download-stream', () => {
.file('test-key-0')

assert.deepEqual(await downloadStream({ file }), 'read-stream')
assert.deepEqual(file.createReadStream.args[0], [ undefined ])
assert.deepEqual(file.createReadStream.args[0], [undefined])
})
})
2 changes: 1 addition & 1 deletion lib/methods/move-file.test.js
Expand Up @@ -22,6 +22,6 @@ describe('move-file', () => {
.file('test-key-1')

await moveFile({ file: sourceFile }, { file: destFile })
assert.deepEqual(sourceFile.move.args[0], [ destFile ])
assert.deepEqual(sourceFile.move.args[0], [destFile])
})
})
6 changes: 3 additions & 3 deletions lib/mock-storage.js
Expand Up @@ -26,10 +26,10 @@ module.exports = (sandbox) => {
createReadStream: sandbox.stub().callsFake(() => 'read-stream'),
createWriteStream: sandbox.stub().callsFake(() => through2()),
copy: sandbox.stub().callsFake(async () => 'copy'),
download: sandbox.stub().callsFake(async () => 'download'),
download: sandbox.stub().callsFake(async () => ['download']),
exists: sandbox.stub().callsFake(async () => 'exists'),
getSignedUrl: sandbox.stub().callsFake(async () => [ 'signed-url' ]),
getMetadata: sandbox.stub().callsFake(async () => [ { size: '-1' } ]),
getSignedUrl: sandbox.stub().callsFake(async () => ['signed-url']),
getMetadata: sandbox.stub().callsFake(async () => [{ size: '-1' }]),
move: sandbox.stub().callsFake(async () => 'move'),
save: sandbox.stub().callsFake(async () => 'save')
}
Expand Down
2 changes: 1 addition & 1 deletion lib/resolve-options.js
Expand Up @@ -42,7 +42,7 @@ module.exports = (defaultOptions, options) => {
const key = opts.key && normalizeKey(opts.key)
const file = opts.file || (key && bucket && bucket.file(key))

const contextKeys = [ 'validate', 'url', 'key', 'bucket' ].concat(storageKeys)
const contextKeys = ['validate', 'url', 'key', 'bucket'].concat(storageKeys)

const blacklistKeys = contextKeys.map(key => `!${key}`)
const remainingOpts = filter(opts, ['*'].concat(blacklistKeys))
Expand Down
18 changes: 9 additions & 9 deletions lib/resolve-options.test.js
Expand Up @@ -27,9 +27,9 @@ describe('resolve-options', () => {
extraFlag: { deep: true }
})

assert.deepEqual(resolveOptions.Storage.args[0], [ { projectId: 'test-project-id-0' } ])
assert.deepEqual(res.storage.bucket.args[0], [ 'test-bucket-0' ])
assert.deepEqual(res.bucket.file.args[0], [ 'test-key-0' ])
assert.deepEqual(resolveOptions.Storage.args[0], [{ projectId: 'test-project-id-0' }])
assert.deepEqual(res.storage.bucket.args[0], ['test-bucket-0'])
assert.deepEqual(res.bucket.file.args[0], ['test-key-0'])

assert.deepEqual(res.url, 'gs://test-bucket-0/test-key-0')
assert.deepEqual(res.extraFlag, { deep: true })
Expand All @@ -46,9 +46,9 @@ describe('resolve-options', () => {
url: 'gs://test-bucket-1/test-key-1.test'
})

assert.deepEqual(resolveOptions.Storage.args[0], [ { } ])
assert.deepEqual(res.storage.bucket.args[0], [ 'test-bucket-1' ])
assert.deepEqual(res.bucket.file.args[0], [ 'test-key-1.test' ])
assert.deepEqual(resolveOptions.Storage.args[0], [{ }])
assert.deepEqual(res.storage.bucket.args[0], ['test-bucket-1'])
assert.deepEqual(res.bucket.file.args[0], ['test-key-1.test'])

assert.deepEqual(res.url, 'gs://test-bucket-1/test-key-1.test')

Expand All @@ -61,8 +61,8 @@ describe('resolve-options', () => {
bucket: 'test-bucket-2'
})

assert.deepEqual(resolveOptions.Storage.args[0], [ { } ])
assert.deepEqual(res.storage.bucket.args[0], [ 'test-bucket-2' ])
assert.deepEqual(resolveOptions.Storage.args[0], [{ }])
assert.deepEqual(res.storage.bucket.args[0], ['test-bucket-2'])
assert.deepEqual(res.bucket.file.callCount, 0)

assert.ok(res.bucket)
Expand All @@ -78,7 +78,7 @@ describe('resolve-options', () => {
throw new Error()
} catch (err) {
assert.deepEqual(err.message, 'missing required param "bucket"')
assert.deepEqual(resolveOptions.Storage.args[0], [ { } ])
assert.deepEqual(resolveOptions.Storage.args[0], [{ }])
}
})
})
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -40,7 +40,7 @@
"mocha-standard": "^1.0.0",
"mock-fs": "^4.3.0",
"sinon": "^4.5.0",
"standard": "^11.0.1"
"standard": "^14.3.0"
},
"standard": {
"globals": [
Expand Down

0 comments on commit 33eb1f7

Please sign in to comment.