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

Set artifact file path for the Google provider. #200

Merged
merged 1 commit into from
Aug 22, 2017
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
4 changes: 4 additions & 0 deletions lib/packageModules.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,10 @@ module.exports = {
const func = this.serverless.service.getFunction(funcName);
setArtifactPath.call(this, func, path.relative(this.serverless.config.servicePath, artifacts[0]));
});
// For Google set the service artifact path
if (_.get(this.serverless, 'service.provider.name') === 'google') {
_.set(this.serverless, 'service.package.artifact', path.relative(this.serverless.config.servicePath, artifacts[0]));
}
}

return null;
Expand Down
50 changes: 50 additions & 0 deletions tests/packageModules.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,56 @@ describe('packageModules', () => {
]));
});

it('should set the service artifact path with the Google provider', () => {
// Test data
const stats = {
stats: [
{
compilation: {
compiler: {
outputPath: '/my/Service/Path/.webpack/service'
}
}
}
]
};
const files = [
'README.md', 'index.js'
];
const allFunctions = [ 'func1', 'func2' ];
const func1 = {
handler: 'handler1',
events: []
};
const func2 = {
handler: 'handler2',
events: []
};
// Setup sandbox and behavior for service packaging
sandbox.stub(module, 'entryFunctions').value(undefined);
// Serverless behavior
sandbox.stub(serverless.service.provider, 'name').value('google');
sandbox.stub(serverless.config, 'servicePath').value('/my/Service/Path');
sandbox.stub(serverless.service.package, 'individually').value(false);
getVersionStub.returns('1.18.0');
getServiceObjectStub.returns({
name: 'test-service'
});
getAllFunctionsStub.returns(allFunctions);
getFunctionStub.withArgs('func1').returns(func1);
getFunctionStub.withArgs('func2').returns(func2);
// Mock behavior
globMock.sync.returns(files);
fsMock._streamMock.on.withArgs('open').yields();
fsMock._streamMock.on.withArgs('close').yields();
fsMock._statMock.isDirectory.returns(false);

const expectedArtifactPath = path.join('.serverless', 'test-service.zip');

return expect(module.packageModules(stats)).to.be.fulfilled
.then(() => expect(serverless.service).to.have.a.nested.property('package.artifact').that.equals(expectedArtifactPath));
});

it('should package with individual packaging', () => {
// Test data
const stats = {
Expand Down
39 changes: 39 additions & 0 deletions tests/validate.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,18 @@ describe('validate', () => {
},
};

const testFunctionsGoogleConfig = {
func1: {
handler: 'func1handler',
events: [{
http: {
method: 'get',
path: 'func1path',
},
}],
},
};

it('should expose all functions if `options.function` is not defined', () => {
const testOutPath = 'test';
const testConfig = {
Expand Down Expand Up @@ -375,6 +387,33 @@ describe('validate', () => {
});
});

it('should ignore entry points for the Google provider', () => {
const testOutPath = 'test';
const testFunction = 'func1';
const testConfig = {
entry: './index.js',
target: 'node',
output: {
path: testOutPath,
filename: 'index.js'
},
};
sandbox.stub(module.serverless, 'service.provider.name').value('google');
module.serverless.service.custom.webpack = testConfig;
module.serverless.service.functions = testFunctionsGoogleConfig;
module.options.function = testFunction;
globSyncStub.returns([]);
return expect(module.validate()).to.be.fulfilled
.then(() => {
const lib = require('../lib/index');

expect(lib.entries).to.deep.equal({});
expect(globSyncStub).to.not.have.been.called;
expect(serverless.cli.log).to.not.have.been.called;
return null;
});
});

it('should show a warning if more than one matching handler is found', () => {
const testOutPath = 'test';
const testFunction = 'func1';
Expand Down