diff --git a/packages/@aws-cdk/cloudformation-include/test/test-templates/yaml/year-month-date-as-strings.yaml b/packages/@aws-cdk/cloudformation-include/test/test-templates/yaml/year-month-date-as-strings.yaml new file mode 100644 index 0000000000000..f25f363879810 --- /dev/null +++ b/packages/@aws-cdk/cloudformation-include/test/test-templates/yaml/year-month-date-as-strings.yaml @@ -0,0 +1,14 @@ +AWSTemplateFormatVersion: 2010-09-09 +Resources: + Role: + Type: AWS::IAM::Role + Properties: + AssumeRolePolicyDocument: + Version: 2012-10-17 + Statement: + - Effect: Allow + Principal: + Service: + - ec2.amazonaws.com + Action: + - sts:AssumeRole diff --git a/packages/@aws-cdk/cloudformation-include/test/yaml-templates.test.ts b/packages/@aws-cdk/cloudformation-include/test/yaml-templates.test.ts index 5faf8bd1a5e1c..0724020f90f56 100644 --- a/packages/@aws-cdk/cloudformation-include/test/yaml-templates.test.ts +++ b/packages/@aws-cdk/cloudformation-include/test/yaml-templates.test.ts @@ -23,6 +23,33 @@ describe('CDK Include', () => { ); }); + test('can ingest a template with year-month-date parsed as string instead of Date', () => { + includeTestTemplate(stack, 'year-month-date-as-strings.yaml'); + + expect(stack).toMatchTemplate({ + "AWSTemplateFormatVersion": "2010-09-09", + "Resources": { + "Role": { + "Type": "AWS::IAM::Role", + "Properties": { + "AssumeRolePolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Effect": "Allow", + "Principal": { + "Service": ["ec2.amazonaws.com"], + }, + "Action": ["sts:AssumeRole"], + }, + ], + }, + }, + }, + }, + }); + }); + test('can ingest a template with the short form Base64 function', () => { includeTestTemplate(stack, 'short-form-base64.yaml'); diff --git a/packages/@aws-cdk/yaml-cfn/lib/yaml.ts b/packages/@aws-cdk/yaml-cfn/lib/yaml.ts index eca37db0ed048..e46c8f8d6bf72 100644 --- a/packages/@aws-cdk/yaml-cfn/lib/yaml.ts +++ b/packages/@aws-cdk/yaml-cfn/lib/yaml.ts @@ -54,6 +54,6 @@ const shortForms: yaml_types.Schema.CustomTag[] = [ function parseYamlStrWithCfnTags(text: string): any { return yaml.parse(text, { customTags: shortForms, - schema: 'yaml-1.1', + schema: 'core', }); } diff --git a/packages/@aws-cdk/yaml-cfn/test/deserialization.test.ts b/packages/@aws-cdk/yaml-cfn/test/deserialization.test.ts new file mode 100644 index 0000000000000..e2a3688393b61 --- /dev/null +++ b/packages/@aws-cdk/yaml-cfn/test/deserialization.test.ts @@ -0,0 +1,34 @@ +import '@aws-cdk/assert/jest'; +import * as yaml_cfn from '../lib'; + +test('Unquoted year-month-day is treated as a string, not a Date', () => { + const value = yaml_cfn.deserialize('Key: 2020-12-31'); + + expect(value).toEqual({ + Key: '2020-12-31', + }); +}); + +test("Unquoted 'No' is treated as a string, not a boolean", () => { + const value = yaml_cfn.deserialize('Key: No'); + + expect(value).toEqual({ + Key: 'No', + }); +}); + +test("Short-form 'Ref' is deserialized correctly", () => { + const value = yaml_cfn.deserialize('!Ref Resource'); + + expect(value).toEqual({ + Ref: 'Resource', + }); +}); + +test("Short-form 'Fn::GetAtt' is deserialized correctly", () => { + const value = yaml_cfn.deserialize('!GetAtt Resource.Attribute'); + + expect(value).toEqual({ + 'Fn::GetAtt': 'Resource.Attribute', + }); +}); diff --git a/packages/@aws-cdk/yaml-cfn/test/serialization.test.ts b/packages/@aws-cdk/yaml-cfn/test/serialization.test.ts new file mode 100644 index 0000000000000..bbc3a45d6ac26 --- /dev/null +++ b/packages/@aws-cdk/yaml-cfn/test/serialization.test.ts @@ -0,0 +1,8 @@ +import '@aws-cdk/assert/jest'; +import * as yaml_cfn from '../lib'; + +test('An object with a single string value is serialized as a simple string', () => { + const value = yaml_cfn.serialize({ key: 'some string' }); + + expect(value).toEqual('key: some string\n'); +}); diff --git a/packages/@aws-cdk/yaml-cfn/test/yaml.test.ts b/packages/@aws-cdk/yaml-cfn/test/yaml.test.ts deleted file mode 100644 index f8ce8131c4de7..0000000000000 --- a/packages/@aws-cdk/yaml-cfn/test/yaml.test.ts +++ /dev/null @@ -1,5 +0,0 @@ -import '@aws-cdk/assert/jest'; - -test('No tests are specified for this package', () => { - expect(true).toBe(true); -});