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

Remove default stage value in provider object #6200

Merged
merged 3 commits into from Jun 21, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 0 additions & 1 deletion lib/classes/Service.js
Expand Up @@ -20,7 +20,6 @@ class Service {
this.serviceObject = null; this.serviceObject = null;
this.provider = { this.provider = {
stage: 'dev', stage: 'dev',
region: 'us-east-1',
variableSyntax: '\\${([ ~:a-zA-Z0-9._@\'",\\-\\/\\(\\)*]+?)}', variableSyntax: '\\${([ ~:a-zA-Z0-9._@\'",\\-\\/\\(\\)*]+?)}',
}; };
this.custom = {}; this.custom = {};
Expand Down
219 changes: 109 additions & 110 deletions lib/classes/Service.test.js
Expand Up @@ -30,7 +30,6 @@ describe('Service', () => {
expect(serviceInstance.serviceObject).to.be.equal(null); expect(serviceInstance.serviceObject).to.be.equal(null);
expect(serviceInstance.provider).to.deep.equal({ expect(serviceInstance.provider).to.deep.equal({
stage: 'dev', stage: 'dev',
region: 'us-east-1',
variableSyntax: '\\${([ ~:a-zA-Z0-9._@\'",\\-\\/\\(\\)*]+?)}', variableSyntax: '\\${([ ~:a-zA-Z0-9._@\'",\\-\\/\\(\\)*]+?)}',
}); });
expect(serviceInstance.custom).to.deep.equal({}); expect(serviceInstance.custom).to.deep.equal({});
Expand Down Expand Up @@ -268,23 +267,23 @@ describe('Service', () => {
serviceInstance = new Service(serverless); serviceInstance = new Service(serverless);


return expect(serviceInstance.load()).to.eventually.be.fulfilled return expect(serviceInstance.load()).to.eventually.be.fulfilled
.then(() => { .then(() => {
expect(serviceInstance.service).to.be.equal('new-service'); expect(serviceInstance.service).to.be.equal('new-service');
expect(serviceInstance.provider.name).to.deep.equal('aws'); expect(serviceInstance.provider.name).to.deep.equal('aws');
expect(serviceInstance.provider.variableSyntax).to.equal( expect(serviceInstance.provider.variableSyntax).to.equal(
'\\${{([ ~:a-zA-Z0-9._@\'",\\-\\/\\(\\)*]+?)}}' '\\${{([ ~:a-zA-Z0-9._@\'",\\-\\/\\(\\)*]+?)}}'
); );
expect(serviceInstance.plugins).to.deep.equal(['testPlugin']); expect(serviceInstance.plugins).to.deep.equal(['testPlugin']);
expect(serviceInstance.resources.aws).to.deep.equal({ resourcesProp: 'value' }); expect(serviceInstance.resources.aws).to.deep.equal({ resourcesProp: 'value' });
expect(serviceInstance.resources.azure).to.deep.equal({}); expect(serviceInstance.resources.azure).to.deep.equal({});
expect(serviceInstance.resources.google).to.deep.equal({}); expect(serviceInstance.resources.google).to.deep.equal({});
expect(serviceInstance.package.exclude.length).to.equal(1); expect(serviceInstance.package.exclude.length).to.equal(1);
expect(serviceInstance.package.exclude[0]).to.equal('exclude-me'); expect(serviceInstance.package.exclude[0]).to.equal('exclude-me');
expect(serviceInstance.package.include.length).to.equal(1); expect(serviceInstance.package.include.length).to.equal(1);
expect(serviceInstance.package.include[0]).to.equal('include-me'); expect(serviceInstance.package.include[0]).to.equal('include-me');
expect(serviceInstance.package.artifact).to.equal('some/path/foo.zip'); expect(serviceInstance.package.artifact).to.equal('some/path/foo.zip');
expect(serviceInstance.package.excludeDevDependencies).to.equal(undefined); expect(serviceInstance.package.excludeDevDependencies).to.equal(undefined);
}); });
}); });


it('should load serverless.js from filesystem', () => { it('should load serverless.js from filesystem', () => {
Expand Down Expand Up @@ -323,23 +322,23 @@ describe('Service', () => {
serviceInstance = new Service(serverless); serviceInstance = new Service(serverless);


return expect(serviceInstance.load()).to.eventually.be.fulfilled return expect(serviceInstance.load()).to.eventually.be.fulfilled
.then(() => { .then(() => {
expect(serviceInstance.service).to.be.equal('new-service'); expect(serviceInstance.service).to.be.equal('new-service');
expect(serviceInstance.provider.name).to.deep.equal('aws'); expect(serviceInstance.provider.name).to.deep.equal('aws');
expect(serviceInstance.provider.variableSyntax).to.equal( expect(serviceInstance.provider.variableSyntax).to.equal(
'\\${{([ ~:a-zA-Z0-9._@\'",\\-\\/\\(\\)*]+?)}}' '\\${{([ ~:a-zA-Z0-9._@\'",\\-\\/\\(\\)*]+?)}}'
); );
expect(serviceInstance.plugins).to.deep.equal(['testPlugin']); expect(serviceInstance.plugins).to.deep.equal(['testPlugin']);
expect(serviceInstance.resources.aws).to.deep.equal({ resourcesProp: 'value' }); expect(serviceInstance.resources.aws).to.deep.equal({ resourcesProp: 'value' });
expect(serviceInstance.resources.azure).to.deep.equal({}); expect(serviceInstance.resources.azure).to.deep.equal({});
expect(serviceInstance.resources.google).to.deep.equal({}); expect(serviceInstance.resources.google).to.deep.equal({});
expect(serviceInstance.package.exclude.length).to.equal(1); expect(serviceInstance.package.exclude.length).to.equal(1);
expect(serviceInstance.package.exclude[0]).to.equal('exclude-me'); expect(serviceInstance.package.exclude[0]).to.equal('exclude-me');
expect(serviceInstance.package.include.length).to.equal(1); expect(serviceInstance.package.include.length).to.equal(1);
expect(serviceInstance.package.include[0]).to.equal('include-me'); expect(serviceInstance.package.include[0]).to.equal('include-me');
expect(serviceInstance.package.artifact).to.equal('some/path/foo.zip'); expect(serviceInstance.package.artifact).to.equal('some/path/foo.zip');
expect(serviceInstance.package.excludeDevDependencies).to.equal(undefined); expect(serviceInstance.package.excludeDevDependencies).to.equal(undefined);
}); });
}); });


it('should load serverless.js from filesystem', () => { it('should load serverless.js from filesystem', () => {
Expand Down Expand Up @@ -378,23 +377,23 @@ describe('Service', () => {
serviceInstance = new Service(serverless); serviceInstance = new Service(serverless);


return expect(serviceInstance.load()).to.eventually.be.fulfilled return expect(serviceInstance.load()).to.eventually.be.fulfilled
.then(() => { .then(() => {
expect(serviceInstance.service).to.be.equal('new-service'); expect(serviceInstance.service).to.be.equal('new-service');
expect(serviceInstance.provider.name).to.deep.equal('aws'); expect(serviceInstance.provider.name).to.deep.equal('aws');
expect(serviceInstance.provider.variableSyntax).to.equal( expect(serviceInstance.provider.variableSyntax).to.equal(
'\\${{([ ~:a-zA-Z0-9._\'",\\-\\/\\(\\)]+?)}}' '\\${{([ ~:a-zA-Z0-9._\'",\\-\\/\\(\\)]+?)}}'
); );
expect(serviceInstance.plugins).to.deep.equal(['testPlugin']); expect(serviceInstance.plugins).to.deep.equal(['testPlugin']);
expect(serviceInstance.resources.aws).to.deep.equal({ resourcesProp: 'value' }); expect(serviceInstance.resources.aws).to.deep.equal({ resourcesProp: 'value' });
expect(serviceInstance.resources.azure).to.deep.equal({}); expect(serviceInstance.resources.azure).to.deep.equal({});
expect(serviceInstance.resources.google).to.deep.equal({}); expect(serviceInstance.resources.google).to.deep.equal({});
expect(serviceInstance.package.exclude.length).to.equal(1); expect(serviceInstance.package.exclude.length).to.equal(1);
expect(serviceInstance.package.exclude[0]).to.equal('exclude-me'); expect(serviceInstance.package.exclude[0]).to.equal('exclude-me');
expect(serviceInstance.package.include.length).to.equal(1); expect(serviceInstance.package.include.length).to.equal(1);
expect(serviceInstance.package.include[0]).to.equal('include-me'); expect(serviceInstance.package.include[0]).to.equal('include-me');
expect(serviceInstance.package.artifact).to.equal('some/path/foo.zip'); expect(serviceInstance.package.artifact).to.equal('some/path/foo.zip');
expect(serviceInstance.package.excludeDevDependencies).to.equal(undefined); expect(serviceInstance.package.excludeDevDependencies).to.equal(undefined);
}); });
}); });


it('should throw error if serverless.js exports invalid config', () => { it('should throw error if serverless.js exports invalid config', () => {
Expand Down Expand Up @@ -451,10 +450,10 @@ describe('Service', () => {
serviceInstance = new Service(serverless); serviceInstance = new Service(serverless);


return expect(serviceInstance.load()).to.eventually.be.fulfilled return expect(serviceInstance.load()).to.eventually.be.fulfilled
.then(() => { .then(() => {
// YAML should have been loaded instead of JSON // YAML should have been loaded instead of JSON
expect(serviceInstance.service).to.be.equal('YAML service'); expect(serviceInstance.service).to.be.equal('YAML service');
}); });
}); });


it('should reject when the service name is missing', () => { it('should reject when the service name is missing', () => {
Expand Down Expand Up @@ -491,10 +490,10 @@ describe('Service', () => {
serviceInstance = new Service(serverless); serviceInstance = new Service(serverless);


return expect(serviceInstance.load()).to.eventually.be.fulfilled return expect(serviceInstance.load()).to.eventually.be.fulfilled
.then(() => { .then(() => {
expect(serviceInstance.service).to.equal('my-service'); expect(serviceInstance.service).to.equal('my-service');
expect(serviceInstance.serviceObject).to.deep.equal(serverlessYaml.service); expect(serviceInstance.serviceObject).to.deep.equal(serverlessYaml.service);
}); });
}); });


it('should support Serverless file with a non-aws provider', () => { it('should support Serverless file with a non-aws provider', () => {
Expand All @@ -516,18 +515,18 @@ describe('Service', () => {
serviceInstance = new Service(serverless); serviceInstance = new Service(serverless);


return expect(serviceInstance.load()).to.eventually.be.fulfilled return expect(serviceInstance.load()).to.eventually.be.fulfilled
.then(() => { .then(() => {
serviceInstance.setFunctionNames(); serviceInstance.setFunctionNames();
const expectedFunc = { const expectedFunc = {
functionA: { functionA: {
name: 'customFunctionName', name: 'customFunctionName',
events: [], events: [],
}, },
}; };
expect(serviceInstance.service).to.be.equal('my-service'); expect(serviceInstance.service).to.be.equal('my-service');
expect(serviceInstance.provider.name).to.deep.equal('openwhisk'); expect(serviceInstance.provider.name).to.deep.equal('openwhisk');
expect(serviceInstance.functions).to.deep.equal(expectedFunc); expect(serviceInstance.functions).to.deep.equal(expectedFunc);
}); });
}); });


it('should support Serverless file with a .yaml extension', () => { it('should support Serverless file with a .yaml extension', () => {
Expand All @@ -549,18 +548,18 @@ describe('Service', () => {
serviceInstance = new Service(serverless); serviceInstance = new Service(serverless);


return expect(serviceInstance.load()).to.eventually.be.fulfilled return expect(serviceInstance.load()).to.eventually.be.fulfilled
.then(() => { .then(() => {
serviceInstance.setFunctionNames(); serviceInstance.setFunctionNames();
const expectedFunc = { const expectedFunc = {
functionA: { functionA: {
name: 'customFunctionName', name: 'customFunctionName',
events: [], events: [],
}, },
}; };
expect(serviceInstance.service).to.be.equal('my-service'); expect(serviceInstance.service).to.be.equal('my-service');
expect(serviceInstance.provider.name).to.deep.equal('aws'); expect(serviceInstance.provider.name).to.deep.equal('aws');
expect(serviceInstance.functions).to.deep.equal(expectedFunc); expect(serviceInstance.functions).to.deep.equal(expectedFunc);
}); });
}); });


it('should support Serverless file with a .yml extension', () => { it('should support Serverless file with a .yml extension', () => {
Expand All @@ -580,18 +579,18 @@ describe('Service', () => {
serviceInstance = new Service(serverless); serviceInstance = new Service(serverless);


return expect(serviceInstance.load({ stage: 'dev' })).to.eventually.be.fulfilled return expect(serviceInstance.load({ stage: 'dev' })).to.eventually.be.fulfilled
.then(() => { .then(() => {
serviceInstance.setFunctionNames(); serviceInstance.setFunctionNames();
const expectedFunc = { const expectedFunc = {
functionA: { functionA: {
name: 'my-service-dev-functionA', name: 'my-service-dev-functionA',
events: [], events: [],
}, },
}; };
expect(serviceInstance.service).to.be.equal('my-service'); expect(serviceInstance.service).to.be.equal('my-service');
expect(serviceInstance.provider.name).to.deep.equal('aws'); expect(serviceInstance.provider.name).to.deep.equal('aws');
expect(serviceInstance.functions).to.deep.equal(expectedFunc); expect(serviceInstance.functions).to.deep.equal(expectedFunc);
}); });
}); });


it('should reject if service property is missing', () => { it('should reject if service property is missing', () => {
Expand Down Expand Up @@ -679,15 +678,15 @@ describe('Service', () => {
serviceInstance = new Service(serverless); serviceInstance = new Service(serverless);


return expect(serviceInstance.load()).to.eventually.be.fulfilled return expect(serviceInstance.load()).to.eventually.be.fulfilled
.then(() => { .then(() => {
// populate variables in service configuration // populate variables in service configuration
serverless.variables.populateService(); serverless.variables.populateService();


// validate the service configuration, now that variables are loaded // validate the service configuration, now that variables are loaded
serviceInstance.validate(); serviceInstance.validate();


expect(serviceInstance.functions).to.deep.equal({}); expect(serviceInstance.functions).to.deep.equal({});
}); });
}); });
}); });


Expand Down Expand Up @@ -716,11 +715,11 @@ describe('Service', () => {
serverless.service = new Service(serverless); serverless.service = new Service(serverless);


return expect(serverless.service.load()).to.eventually.be.fulfilled return expect(serverless.service.load()).to.eventually.be.fulfilled
.then(() => { .then(() => {
// validate the service configuration, now that variables are loaded // validate the service configuration, now that variables are loaded
expect(() => serverless.service.validate()) expect(() => serverless.service.validate())
.to.throw('Events for "functionA" must be an array, not an string'); .to.throw('Events for "functionA" must be an array, not an string');
}); });
}); });


describe('stage name validation', () => { describe('stage name validation', () => {
Expand All @@ -734,7 +733,7 @@ describe('Service', () => {
} }


it(`should not throw an error if http event is absent and it(`should not throw an error if http event is absent and
stage contains only alphanumeric, underscore and hyphen`, function () { stage contains only alphanumeric, underscore and hyphen`, function () {
this.timeout(10000); // Occasionally times out with default settings this.timeout(10000); // Occasionally times out with default settings
const SUtils = new Utils(); const SUtils = new Utils();
const serverlessYml = { const serverlessYml = {
Expand All @@ -759,7 +758,7 @@ describe('Service', () => {
}); });


it(`should not throw an error after variable population if http event is present and it(`should not throw an error after variable population if http event is present and
the populated stage contains only alphanumeric, underscore and hyphen`, () => { the populated stage contains only alphanumeric, underscore and hyphen`, () => {
const SUtils = new Utils(); const SUtils = new Utils();
const serverlessYml = { const serverlessYml = {
service: 'new-service', service: 'new-service',
Expand Down