Skip to content

Commit

Permalink
add unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
Niranjan Jayakar committed Mar 6, 2020
1 parent 252a88b commit dc9d837
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 3 deletions.
10 changes: 7 additions & 3 deletions packages/@aws-cdk/cfnspec/build-tools/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,7 @@ async function main() {
}
}

detectScrutinyTypes(spec);
replaceIncompleteTypes(spec);
dropTypelessAttributes(spec);
massageSpec(spec);

spec.Fingerprint = md5(JSON.stringify(normalize(spec)));

Expand All @@ -37,6 +35,12 @@ async function main() {
await fs.writeJson(path.join(outDir, 'specification.json'), spec, { spaces: 2 });
}

export function massageSpec(spec: schema.Specification) {
detectScrutinyTypes(spec);
replaceIncompleteTypes(spec);
dropTypelessAttributes(spec);
}

function forEachSection(spec: schema.Specification, data: any, cb: (spec: any, fragment: any, path: string[]) => void) {
cb(spec.PropertyTypes, data.PropertyTypes, ['PropertyTypes']);
cb(spec.ResourceTypes, data.ResourceTypes, ['ResourceTypes']);
Expand Down
68 changes: 68 additions & 0 deletions packages/@aws-cdk/cfnspec/test/test.build.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import { Test } from 'nodeunit';
import { massageSpec } from '../build-tools/build';
import { schema } from '../lib';

export = {
'dropTypelessAttributes works correctly'(test: Test) {
const spec: schema.Specification = {
Fingerprint: 'some-fingerprint',
PropertyTypes: {
'CDK::Test::Property': {
Properties: {
Type: ({
PrimitiveType: "String",
} as schema.ScalarProperty), // ts is being weird and doesn't correctly match the type
},
}
},
ResourceTypes: {
'CDK::Test::Resource': {
Attributes: {
Attribute1: ({
PrimitiveType: 'String'
} as schema.PrimitiveAttribute), // ts is being weird and doesn't correctly match the type
Attribute2: ({} as schema.PrimitiveAttribute),
},
Documentation: "https://documentation-url/cdk/test/resource",
Properties: {
ResourceArn: ({
PrimitiveType: "String",
} as schema.PrimitiveProperty), // ts is being weird and doesn't correctly match the type
}
}
}
};

massageSpec(spec);

test.deepEqual(spec, {
Fingerprint: 'some-fingerprint',
PropertyTypes: {
'CDK::Test::Property': {
Properties: {
Type: ({
PrimitiveType: "String",
} as schema.ScalarProperty), // ts is being weird and doesn't correctly match the type
},
}
},
ResourceTypes: {
'CDK::Test::Resource': {
Attributes: {
Attribute1: ({
PrimitiveType: 'String'
}),
},
Documentation: "https://documentation-url/cdk/test/resource",
Properties: {
ResourceArn: {
PrimitiveType: "String",
},
}
}
}
});

test.done();
}
};

0 comments on commit dc9d837

Please sign in to comment.