Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Configure aws sdk #3

Merged
merged 2 commits into from
Oct 2, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
});
});
});