Skip to content

Commit

Permalink
Merge pull request #3 from maafk/configure-aws-sdk
Browse files Browse the repository at this point in the history
Configure aws sdk
  • Loading branch information
maafk authored Oct 2, 2019
2 parents acab717 + af8ae41 commit 017975f
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 5 deletions.
8 changes: 4 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ class ServerlessPrivateAWSRegions {
'before:deploy:deploy': this.prepRegion.bind(this),
'before:remove:remove': this.prepRegion.bind(this),
'before:deploy:function:initialize': this.prepRegion.bind(this),
'before:invoke:invoke': this.prepRegion.bind(this),
'before:info:info': this.prepRegion.bind(this),
'before:rollback:initialize': this.prepRegion.bind(this),
'before:logs:logs': this.prepRegion.bind(this),
'after:aws:package:finalize:mergeCustomProviderResources': this.updatePrincipals.bind(
this
)
Expand Down Expand Up @@ -202,10 +206,6 @@ class ServerlessPrivateAWSRegions {
}
}

alterFiles() {
this.alterS3EndpointFunction();
}

setup() {
this.pluginLog('Running setup for private region');
this.alterS3EndpointFunction();
Expand Down
32 changes: 31 additions & 1 deletion index.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
'use strict';
const fs = require('fs');
const Plugin = require('.');
const Serverless = require('serverless/lib/Serverless');
const AwsProvider = require('serverless/lib/plugins/aws/provider/awsProvider');
Expand Down Expand Up @@ -219,6 +220,8 @@ describe('Using the serverless private aws regions plugin', () => {
describe('Alter S3 endpoint function', () => {
let serverless;
let plugin;
let tmpPath = 'plugins/aws/utils';
let tmpFile = 'getS3EndpointForRegion.js';

beforeEach(() => {
serverless = new Serverless();
Expand All @@ -237,10 +240,37 @@ describe('Using the serverless private aws regions plugin', () => {
}
}
};

fs.mkdirSync(tmpPath, { recursive: true });
fs.copyFileSync(
`${serverless.config.serverlessPath}/${tmpPath}/${tmpFile}`,
`./${tmpPath}/${tmpFile}`
);
serverless.config.serverlessPath = '.';
plugin = new Plugin(serverless);
});
afterEach(() => {
fs.unlinkSync(`./${tmpPath}/${tmpFile}`);
fs.unlinkSync(`./${tmpPath}/${tmpFile}.orig`);
let spl = tmpPath.split('/');
for (let i = 0; i < spl.length; i++) {
fs.rmdirSync(spl.join('/'));
spl.pop();
}
});

test('alterS3EndpointFunction updates the file', () => {});
test('alterS3EndpointFunction updates the file', () => {
plugin.alterS3EndpointFunction();
var file_text = fs
.readFileSync(`./${tmpPath}/${tmpFile}`)
.toString()
.split('\n');
let expected_return =
serverless.service.custom.customRegion.s3Endpoint.return;
let matched_return = file_text.filter(item => {
return item.indexOf(expected_return) !== -1;
});
expect(matched_return.length).toBe(1);
});
});
});

0 comments on commit 017975f

Please sign in to comment.