Skip to content

Commit

Permalink
Add test for deployFunction() with artifact
Browse files Browse the repository at this point in the history
  • Loading branch information
darkowlzz committed Jun 29, 2017
1 parent f43a972 commit 6246825
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 3 deletions.
3 changes: 2 additions & 1 deletion lib/plugins/aws/deployFunction/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ class AwsDeployFunction {

deployFunction() {
const functionObject = this.serverless.service.getFunction(this.options.function);
let artifactFilePath = functionObject.artifact;
const funcPackageConfig = functionObject.package || {};
let artifactFilePath = funcPackageConfig.artifact;
// if function artifact is not provided, derive the default artifact path
if (!artifactFilePath) {
const artifactFileName = this.provider.naming
Expand Down
30 changes: 30 additions & 0 deletions lib/plugins/aws/deployFunction/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,5 +139,35 @@ describe('AwsDeployFunction', () => {
fs.statSync.restore();
});
});

describe('when artifact is provided', () => {
let fsReadFileStub;

beforeEach(() => {
fsReadFileStub = sinon.stub(fs, 'readFileSync').returns('some dummy data');
sinon.stub(fs, 'statSync').returns({ size: 2048 });
sinon.stub(serverless.service, 'getFunction').returns({
handler: true,
package: {
artifact: 'foo.zip',
},
});
sinon.stub(awsDeployFunction.provider, 'request').resolves();
});

afterEach(() => {
fs.readFileSync.restore();
fs.statSync.restore();
serverless.service.getFunction.restore();
awsDeployFunction.provider.request.restore();
});

it('should read the provided artifact', () => {
return awsDeployFunction.deployFunction().then(() => {
const expected = 'foo.zip';
expect(fsReadFileStub).to.have.been.calledWithExactly(expected);
});
});
});
});
});
6 changes: 4 additions & 2 deletions lib/plugins/package/lib/packageService.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ module.exports = {
// use the artifact in function config if provided
if (funcPackageConfig.artifact) {
const filePath = path.join(this.serverless.config.servicePath, funcPackageConfig.artifact);
functionObject.artifact = filePath;
functionObject.package.artifact = filePath;
return BbPromise.resolve(filePath);
}

Expand All @@ -83,7 +83,9 @@ module.exports = {
const zipFileName = `${functionName}.zip`;

return this.zipService(exclude, include, zipFileName).then(artifactPath => {
functionObject.artifact = artifactPath;
functionObject.package = {
artifact: artifactPath,
};
return artifactPath;
});
},
Expand Down

0 comments on commit 6246825

Please sign in to comment.