From c10ba46ce7759853d53c48f20452b538989ad5e8 Mon Sep 17 00:00:00 2001 From: David Poetzsch-Heffter Date: Tue, 10 Jan 2017 02:43:39 +0100 Subject: [PATCH] allowing empty params in overrides (#38) --- lib/optionsFromArguments.js | 5 ++++- spec/test.spec.js | 10 ++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/lib/optionsFromArguments.js b/lib/optionsFromArguments.js index e678330..1c694cc 100644 --- a/lib/optionsFromArguments.js +++ b/lib/optionsFromArguments.js @@ -54,7 +54,10 @@ const optionsFromArguments = function optionsFromArguments(args) { } else if (args.length == 2) { Object.assign(options, stringOrOptions); s3overrides = args[1]; - options.bucket = s3overrides.params.Bucket; + + if (s3overrides.params) { + options.bucket = s3overrides.params.Bucket; + } } else if (args.length > 2) { throw new Error('Failed to configure S3Adapter. Arguments don\'t make sense'); } diff --git a/spec/test.spec.js b/spec/test.spec.js index 7709eb4..6384baa 100644 --- a/spec/test.spec.js +++ b/spec/test.spec.js @@ -132,6 +132,16 @@ describe('S3Adapter tests', () => { expect(s3._s3Client.config.params.Bucket).toEqual('bucket-2'); expect(s3._bucketPrefix).toEqual('test/'); }); + + it('should accept overrides without params', () => { + var confObj = { bucketPrefix: 'test/', bucket: 'bucket-1', secretKey: 'secret-1', accessKey: 'key-1' }; + var overridesObj = { secretAccessKey: 'secret-2'}; + var s3 = new S3Adapter(confObj, overridesObj); + expect(s3._s3Client.config.accessKeyId).toEqual('key-1'); + expect(s3._s3Client.config.secretAccessKey).toEqual('secret-2'); + expect(s3._s3Client.config.params.Bucket).toEqual('bucket-1'); + expect(s3._bucketPrefix).toEqual('test/'); + }); }); describe('getFileLocation', () => {