mirror of
https://github.com/serverless/serverless.git
synced 2026-01-25 15:07:39 +00:00
support for nested Input objects
This commit is contained in:
parent
60b4fd5c27
commit
e3750e6400
@ -36,9 +36,13 @@ functions:
|
||||
- schedule:
|
||||
rate: rate(10 minutes)
|
||||
enabled: false
|
||||
input: '{"key": "value"}'
|
||||
input:
|
||||
key1: value1
|
||||
key2: value2
|
||||
stageParams:
|
||||
stage: dev
|
||||
- schedule:
|
||||
rate: cron(0 12 * * ? *)
|
||||
enabled: false
|
||||
inputPath: ''
|
||||
inputPath: '$.stageVariables'
|
||||
```
|
||||
|
||||
@ -42,6 +42,12 @@ class AwsCompileScheduledEvents {
|
||||
State = event.schedule.enabled ? 'ENABLED' : 'DISABLED';
|
||||
Input = event.schedule.input || '';
|
||||
InputPath = event.schedule.inputPath || '';
|
||||
|
||||
if (Input && typeof Input === 'object') {
|
||||
Input = JSON.stringify(Input);
|
||||
}
|
||||
// escape quotes to favor JSON.parse
|
||||
Input = Input.replace(/\"/g,'\\"'); // eslint-disable-line
|
||||
} else if (typeof event.schedule === 'string') {
|
||||
ScheduleExpression = event.schedule;
|
||||
State = 'ENABLED';
|
||||
|
||||
@ -109,7 +109,8 @@ describe('AwsCompileScheduledEvents', () => {
|
||||
schedule: {
|
||||
rate: 'rate(10 minutes)',
|
||||
enabled: false,
|
||||
input: '{}',
|
||||
input: '{"key":"value"}',
|
||||
inputPath: '$.stageVariables',
|
||||
},
|
||||
},
|
||||
],
|
||||
@ -121,11 +122,37 @@ describe('AwsCompileScheduledEvents', () => {
|
||||
expect(awsCompileScheduledEvents.serverless.service
|
||||
.provider.compiledCloudFormationTemplate.Resources.FirstEventsRuleSchedule1
|
||||
.Properties.Targets[0].Input
|
||||
).to.equal('{}');
|
||||
).to.equal('{"key":"value"}');
|
||||
expect(awsCompileScheduledEvents.serverless.service
|
||||
.provider.compiledCloudFormationTemplate.Resources.FirstEventsRuleSchedule1
|
||||
.Properties.Targets[0].InputPath
|
||||
).to.equal('');
|
||||
).to.equal('$.stageVariables');
|
||||
});
|
||||
|
||||
it('should respect input variable as an object', () => {
|
||||
awsCompileScheduledEvents.serverless.service.functions = {
|
||||
first: {
|
||||
events: [
|
||||
{
|
||||
schedule: {
|
||||
rate: 'rate(10 minutes)',
|
||||
enabled: false,
|
||||
input: {
|
||||
key: 'value',
|
||||
},
|
||||
inputPath: '$.stageVariables',
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
||||
|
||||
awsCompileScheduledEvents.compileScheduledEvents();
|
||||
|
||||
expect(awsCompileScheduledEvents.serverless.service
|
||||
.provider.compiledCloudFormationTemplate.Resources.FirstEventsRuleSchedule1
|
||||
.Properties.Targets[0].Input
|
||||
).to.equal('{"key":"value"}');
|
||||
});
|
||||
|
||||
it('should not create corresponding resources when scheduled events are not given', () => {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user