Skip to content

Commit

Permalink
fix input fromText has extra quotations
Browse files Browse the repository at this point in the history
  • Loading branch information
samson-keung committed Oct 25, 2024
1 parent 1447087 commit 5b81a3e
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 10 deletions.
11 changes: 6 additions & 5 deletions packages/@aws-cdk/aws-scheduler-alpha/lib/input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export abstract class ScheduleTargetInput {
* @param text Text to use as the input for the target
*/
public static fromText(text: string): ScheduleTargetInput {
return new FieldAwareEventInput(text);
return new FieldAwareEventInput(text, false);
}

/**
Expand All @@ -28,7 +28,7 @@ export abstract class ScheduleTargetInput {
* @param obj object to use to convert to JSON to use as input for the target
*/
public static fromObject(obj: any): ScheduleTargetInput {
return new FieldAwareEventInput(obj);
return new FieldAwareEventInput(obj, true);
}

protected constructor() {
Expand All @@ -41,7 +41,7 @@ export abstract class ScheduleTargetInput {
}

class FieldAwareEventInput extends ScheduleTargetInput {
constructor(private readonly input: any) {
constructor(private readonly input: any, private readonly toJsonString: boolean) {
super();
}

Expand All @@ -57,10 +57,11 @@ class FieldAwareEventInput extends ScheduleTargetInput {
}

const stack = Stack.of(schedule);
return stack.toJsonString(Tokenization.resolve(this.input, {
const inputString = Tokenization.resolve(this.input, {
scope: schedule,
resolver: new Replacer(),
}));
});
return this.toJsonString ? stack.toJsonString(inputString) : inputString;
}
}

Expand Down
9 changes: 5 additions & 4 deletions packages/@aws-cdk/aws-scheduler-alpha/test/input.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ describe('schedule target input', () => {
Template.fromStack(stack).hasResource('AWS::Scheduler::Schedule', {
Properties: {
Target: {
Input: '"test"',
Input: 'test',
},
},
});
Expand All @@ -52,13 +52,14 @@ describe('schedule target input', () => {
test('create an input from text with a ref inside', () => {
new Schedule(stack, 'MyScheduleDummy', {
schedule: expr,
target: new SomeLambdaTarget(func, ScheduleTargetInput.fromText(stack.account)),
target: new SomeLambdaTarget(func, ScheduleTargetInput.fromText(`a-${stack.account}`)),
});

Template.fromStack(stack).hasResource('AWS::Scheduler::Schedule', {
Properties: {
Target: {
Input: {
'Fn::Join': ['', ['"', { Ref: 'AWS::AccountId' }, '"']],
'Fn::Join': ['', ['a-', { Ref: 'AWS::AccountId' }]],
},
},
},
Expand Down Expand Up @@ -115,7 +116,7 @@ describe('schedule target input', () => {
Template.fromStack(stack).hasResource('AWS::Scheduler::Schedule', {
Properties: {
Target: {
Input: '"Test=<aws.scheduler.schedule-arn>"',
Input: 'Test=<aws.scheduler.schedule-arn>',
},
},
});
Expand Down
5 changes: 4 additions & 1 deletion packages/@aws-cdk/aws-scheduler-alpha/test/integ.schedule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,10 @@ integ.assertions.awsApiCall('SQS', 'receiveMessage', {
QueueUrl: queue.queueUrl,
MaxNumberOfMessages: 10,
}).expect(ExpectedResult.objectLike({
Messages: Match.arrayWith([{ Body: `valueA-${stack.region}` }, { Body: `valueB-${stack.region}` }]),
Messages: Match.arrayWith([
Match.objectLike({ Body: `valueA-${stack.region}` }),
Match.objectLike({ Body: `valueB-${stack.region}` }),
]),
})).waitForAssertions({
totalTimeout: cdk.Duration.minutes(5),
interval: cdk.Duration.seconds(20),
Expand Down

0 comments on commit 5b81a3e

Please sign in to comment.