Merge pull request #6200 from mydiemho/myho/removeRegionDefaultFromBase

Remove default stage value in provider object
This commit is contained in:
Philipp Muens 2019-06-21 12:54:57 +02:00 committed by GitHub
commit 6d05d83edb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 109 additions and 111 deletions

View File

@ -21,7 +21,6 @@ class Service {
this.serviceObject = null;
this.provider = {
stage: 'dev',
region: 'us-east-1',
variableSyntax: '\\${([ ~:a-zA-Z0-9._@\'",\\-\\/\\(\\)*]+?)}',
};
this.custom = {};

View File

@ -31,7 +31,6 @@ describe('Service', () => {
expect(serviceInstance.serviceObject).to.be.equal(null);
expect(serviceInstance.provider).to.deep.equal({
stage: 'dev',
region: 'us-east-1',
variableSyntax: '\\${([ ~:a-zA-Z0-9._@\'",\\-\\/\\(\\)*]+?)}',
});
expect(serviceInstance.custom).to.deep.equal({});
@ -273,23 +272,23 @@ describe('Service', () => {
serviceInstance = new Service(serverless);
return expect(serviceInstance.load()).to.eventually.be.fulfilled
.then(() => {
expect(serviceInstance.service).to.be.equal('new-service');
expect(serviceInstance.provider.name).to.deep.equal('aws');
expect(serviceInstance.provider.variableSyntax).to.equal(
'\\${{([ ~:a-zA-Z0-9._@\'",\\-\\/\\(\\)*]+?)}}'
);
expect(serviceInstance.plugins).to.deep.equal(['testPlugin']);
expect(serviceInstance.resources.aws).to.deep.equal({ resourcesProp: 'value' });
expect(serviceInstance.resources.azure).to.deep.equal({});
expect(serviceInstance.resources.google).to.deep.equal({});
expect(serviceInstance.package.exclude.length).to.equal(1);
expect(serviceInstance.package.exclude[0]).to.equal('exclude-me');
expect(serviceInstance.package.include.length).to.equal(1);
expect(serviceInstance.package.include[0]).to.equal('include-me');
expect(serviceInstance.package.artifact).to.equal('some/path/foo.zip');
expect(serviceInstance.package.excludeDevDependencies).to.equal(undefined);
});
.then(() => {
expect(serviceInstance.service).to.be.equal('new-service');
expect(serviceInstance.provider.name).to.deep.equal('aws');
expect(serviceInstance.provider.variableSyntax).to.equal(
'\\${{([ ~:a-zA-Z0-9._@\'",\\-\\/\\(\\)*]+?)}}'
);
expect(serviceInstance.plugins).to.deep.equal(['testPlugin']);
expect(serviceInstance.resources.aws).to.deep.equal({ resourcesProp: 'value' });
expect(serviceInstance.resources.azure).to.deep.equal({});
expect(serviceInstance.resources.google).to.deep.equal({});
expect(serviceInstance.package.exclude.length).to.equal(1);
expect(serviceInstance.package.exclude[0]).to.equal('exclude-me');
expect(serviceInstance.package.include.length).to.equal(1);
expect(serviceInstance.package.include[0]).to.equal('include-me');
expect(serviceInstance.package.artifact).to.equal('some/path/foo.zip');
expect(serviceInstance.package.excludeDevDependencies).to.equal(undefined);
});
});
it('should load serverless.js from filesystem', () => {
@ -329,23 +328,23 @@ describe('Service', () => {
serviceInstance = new Service(serverless);
return expect(serviceInstance.load()).to.eventually.be.fulfilled
.then(() => {
expect(serviceInstance.service).to.be.equal('new-service');
expect(serviceInstance.provider.name).to.deep.equal('aws');
expect(serviceInstance.provider.variableSyntax).to.equal(
'\\${{([ ~:a-zA-Z0-9._@\'",\\-\\/\\(\\)*]+?)}}'
);
expect(serviceInstance.plugins).to.deep.equal(['testPlugin']);
expect(serviceInstance.resources.aws).to.deep.equal({ resourcesProp: 'value' });
expect(serviceInstance.resources.azure).to.deep.equal({});
expect(serviceInstance.resources.google).to.deep.equal({});
expect(serviceInstance.package.exclude.length).to.equal(1);
expect(serviceInstance.package.exclude[0]).to.equal('exclude-me');
expect(serviceInstance.package.include.length).to.equal(1);
expect(serviceInstance.package.include[0]).to.equal('include-me');
expect(serviceInstance.package.artifact).to.equal('some/path/foo.zip');
expect(serviceInstance.package.excludeDevDependencies).to.equal(undefined);
});
.then(() => {
expect(serviceInstance.service).to.be.equal('new-service');
expect(serviceInstance.provider.name).to.deep.equal('aws');
expect(serviceInstance.provider.variableSyntax).to.equal(
'\\${{([ ~:a-zA-Z0-9._@\'",\\-\\/\\(\\)*]+?)}}'
);
expect(serviceInstance.plugins).to.deep.equal(['testPlugin']);
expect(serviceInstance.resources.aws).to.deep.equal({ resourcesProp: 'value' });
expect(serviceInstance.resources.azure).to.deep.equal({});
expect(serviceInstance.resources.google).to.deep.equal({});
expect(serviceInstance.package.exclude.length).to.equal(1);
expect(serviceInstance.package.exclude[0]).to.equal('exclude-me');
expect(serviceInstance.package.include.length).to.equal(1);
expect(serviceInstance.package.include[0]).to.equal('include-me');
expect(serviceInstance.package.artifact).to.equal('some/path/foo.zip');
expect(serviceInstance.package.excludeDevDependencies).to.equal(undefined);
});
});
it('should load serverless.js from filesystem', () => {
@ -385,23 +384,23 @@ describe('Service', () => {
serviceInstance = new Service(serverless);
return expect(serviceInstance.load()).to.eventually.be.fulfilled
.then(() => {
expect(serviceInstance.service).to.be.equal('new-service');
expect(serviceInstance.provider.name).to.deep.equal('aws');
expect(serviceInstance.provider.variableSyntax).to.equal(
'\\${{([ ~:a-zA-Z0-9._\'",\\-\\/\\(\\)]+?)}}'
);
expect(serviceInstance.plugins).to.deep.equal(['testPlugin']);
expect(serviceInstance.resources.aws).to.deep.equal({ resourcesProp: 'value' });
expect(serviceInstance.resources.azure).to.deep.equal({});
expect(serviceInstance.resources.google).to.deep.equal({});
expect(serviceInstance.package.exclude.length).to.equal(1);
expect(serviceInstance.package.exclude[0]).to.equal('exclude-me');
expect(serviceInstance.package.include.length).to.equal(1);
expect(serviceInstance.package.include[0]).to.equal('include-me');
expect(serviceInstance.package.artifact).to.equal('some/path/foo.zip');
expect(serviceInstance.package.excludeDevDependencies).to.equal(undefined);
});
.then(() => {
expect(serviceInstance.service).to.be.equal('new-service');
expect(serviceInstance.provider.name).to.deep.equal('aws');
expect(serviceInstance.provider.variableSyntax).to.equal(
'\\${{([ ~:a-zA-Z0-9._\'",\\-\\/\\(\\)]+?)}}'
);
expect(serviceInstance.plugins).to.deep.equal(['testPlugin']);
expect(serviceInstance.resources.aws).to.deep.equal({ resourcesProp: 'value' });
expect(serviceInstance.resources.azure).to.deep.equal({});
expect(serviceInstance.resources.google).to.deep.equal({});
expect(serviceInstance.package.exclude.length).to.equal(1);
expect(serviceInstance.package.exclude[0]).to.equal('exclude-me');
expect(serviceInstance.package.include.length).to.equal(1);
expect(serviceInstance.package.include[0]).to.equal('include-me');
expect(serviceInstance.package.artifact).to.equal('some/path/foo.zip');
expect(serviceInstance.package.excludeDevDependencies).to.equal(undefined);
});
});
it('should throw error if serverless.js exports invalid config', () => {
@ -460,10 +459,10 @@ describe('Service', () => {
serviceInstance = new Service(serverless);
return expect(serviceInstance.load()).to.eventually.be.fulfilled
.then(() => {
// YAML should have been loaded instead of JSON
expect(serviceInstance.service).to.be.equal('YAML service');
});
.then(() => {
// YAML should have been loaded instead of JSON
expect(serviceInstance.service).to.be.equal('YAML service');
});
});
it('should reject when the service name is missing', () => {
@ -502,10 +501,10 @@ describe('Service', () => {
serviceInstance = new Service(serverless);
return expect(serviceInstance.load()).to.eventually.be.fulfilled
.then(() => {
expect(serviceInstance.service).to.equal('my-service');
expect(serviceInstance.serviceObject).to.deep.equal(serverlessYaml.service);
});
.then(() => {
expect(serviceInstance.service).to.equal('my-service');
expect(serviceInstance.serviceObject).to.deep.equal(serverlessYaml.service);
});
});
it('should support Serverless file with a non-aws provider', () => {
@ -528,18 +527,18 @@ describe('Service', () => {
serviceInstance = new Service(serverless);
return expect(serviceInstance.load()).to.eventually.be.fulfilled
.then(() => {
serviceInstance.setFunctionNames();
const expectedFunc = {
functionA: {
name: 'customFunctionName',
events: [],
},
};
expect(serviceInstance.service).to.be.equal('my-service');
expect(serviceInstance.provider.name).to.deep.equal('openwhisk');
expect(serviceInstance.functions).to.deep.equal(expectedFunc);
});
.then(() => {
serviceInstance.setFunctionNames();
const expectedFunc = {
functionA: {
name: 'customFunctionName',
events: [],
},
};
expect(serviceInstance.service).to.be.equal('my-service');
expect(serviceInstance.provider.name).to.deep.equal('openwhisk');
expect(serviceInstance.functions).to.deep.equal(expectedFunc);
});
});
it('should support Serverless file with a .yaml extension', () => {
@ -562,18 +561,18 @@ describe('Service', () => {
serviceInstance = new Service(serverless);
return expect(serviceInstance.load()).to.eventually.be.fulfilled
.then(() => {
serviceInstance.setFunctionNames();
const expectedFunc = {
functionA: {
name: 'customFunctionName',
events: [],
},
};
expect(serviceInstance.service).to.be.equal('my-service');
expect(serviceInstance.provider.name).to.deep.equal('aws');
expect(serviceInstance.functions).to.deep.equal(expectedFunc);
});
.then(() => {
serviceInstance.setFunctionNames();
const expectedFunc = {
functionA: {
name: 'customFunctionName',
events: [],
},
};
expect(serviceInstance.service).to.be.equal('my-service');
expect(serviceInstance.provider.name).to.deep.equal('aws');
expect(serviceInstance.functions).to.deep.equal(expectedFunc);
});
});
it('should support Serverless file with a .yml extension', () => {
@ -594,18 +593,18 @@ describe('Service', () => {
serviceInstance = new Service(serverless);
return expect(serviceInstance.load({ stage: 'dev' })).to.eventually.be.fulfilled
.then(() => {
serviceInstance.setFunctionNames();
const expectedFunc = {
functionA: {
name: 'my-service-dev-functionA',
events: [],
},
};
expect(serviceInstance.service).to.be.equal('my-service');
expect(serviceInstance.provider.name).to.deep.equal('aws');
expect(serviceInstance.functions).to.deep.equal(expectedFunc);
});
.then(() => {
serviceInstance.setFunctionNames();
const expectedFunc = {
functionA: {
name: 'my-service-dev-functionA',
events: [],
},
};
expect(serviceInstance.service).to.be.equal('my-service');
expect(serviceInstance.provider.name).to.deep.equal('aws');
expect(serviceInstance.functions).to.deep.equal(expectedFunc);
});
});
it('should reject if service property is missing', () => {
@ -698,15 +697,15 @@ describe('Service', () => {
serviceInstance = new Service(serverless);
return expect(serviceInstance.load()).to.eventually.be.fulfilled
.then(() => {
// populate variables in service configuration
serverless.variables.populateService();
.then(() => {
// populate variables in service configuration
serverless.variables.populateService();
// validate the service configuration, now that variables are loaded
serviceInstance.validate();
// validate the service configuration, now that variables are loaded
serviceInstance.validate();
expect(serviceInstance.functions).to.deep.equal({});
});
expect(serviceInstance.functions).to.deep.equal({});
});
});
});
@ -736,11 +735,11 @@ describe('Service', () => {
serverless.service = new Service(serverless);
return expect(serverless.service.load()).to.eventually.be.fulfilled
.then(() => {
// validate the service configuration, now that variables are loaded
expect(() => serverless.service.validate())
.to.throw('Events for "functionA" must be an array, not an string');
});
.then(() => {
// validate the service configuration, now that variables are loaded
expect(() => serverless.service.validate())
.to.throw('Events for "functionA" must be an array, not an string');
});
});
describe('stage name validation', () => {
@ -754,7 +753,7 @@ describe('Service', () => {
}
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
const SUtils = new Utils();
const serverlessYml = {
@ -780,7 +779,7 @@ describe('Service', () => {
});
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 serverlessYml = {
service: 'new-service',