Skip to content

Commit

Permalink
Add test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
maafk committed Oct 1, 2019
1 parent acab717 commit c54116d
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 5 deletions.
4 changes: 0 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -202,10 +202,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 c54116d

Please sign in to comment.