Skip to content

Commit

Permalink
test(cdk-graph): add pdk pipeline coverage
Browse files Browse the repository at this point in the history
Ensure that PDKNag and PDKPipeline are handled by cdk graph and plugins.
  • Loading branch information
JeremyJonas authored and agdimech committed Feb 1, 2023
1 parent 3ac998d commit 982cff5
Show file tree
Hide file tree
Showing 9 changed files with 1,047 additions and 1 deletion.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

Large diffs are not rendered by default.

59 changes: 59 additions & 0 deletions packages/cdk-graph-plugin-diagram/test/graphviz/pdk-integ.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*! Copyright [Amazon.com](http://amazon.com/), Inc. or its affiliates. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0 */
import { CdkGraph } from "@aws-prototyping-sdk/cdk-graph";
import { PDKPipelineIntegApp } from "@aws-prototyping-sdk/cdk-graph/test/__fixtures__/pdk-integ";
import * as fs from "fs-extra";
import * as testUtils from "./test-utils";
import { CdkGraphDiagramPlugin } from "../../src";

jest.setTimeout(90000); // CI tests timeout occasionally so increase to large timeout buffer

const makeCdkOutdir = async (name: string) =>
testUtils.makeCdkOutDir("pdk-integ", name);

describe("pdk-integ", () => {
describe("pipeline", () => {
let outdir: string;
let app: PDKPipelineIntegApp;
let graph: CdkGraph;
let plugin: CdkGraphDiagramPlugin;

beforeAll(async () => {
outdir = await makeCdkOutdir("pipeline");

app = new PDKPipelineIntegApp({ outdir });
plugin = new CdkGraphDiagramPlugin();
graph = new CdkGraph(app, {
plugins: [plugin],
});
app.synth();
await graph.report();
});

it("should generate dot artifact", async () => {
expect(plugin.defaultDotArtifact).toBeDefined();
expect(
await fs.pathExists(plugin.defaultDotArtifact!.filepath)
).toBeTruthy();
expect(
testUtils.cleanseDotSnapshot(
await fs.readFile(plugin.defaultDotArtifact!.filepath, {
encoding: "utf-8",
})
)
).toMatchSnapshot();
});

it("should generate png artifact", async () => {
expect(plugin.defaultPngArtifact).toBeDefined();
expect(
await fs.pathExists(plugin.defaultPngArtifact!.filepath)
).toBeTruthy();

await testUtils.expectToMatchImageSnapshot(
plugin.defaultPngArtifact!.filepath,
"pdk-integ-pipeline"
);
});
});
});
8 changes: 8 additions & 0 deletions packages/cdk-graph/.projen/deps.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions packages/cdk-graph/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
},
"devDependencies": {
"@aws-cdk/cfnspec": "^2.60.0",
"@aws-prototyping-sdk/pdk-nag": "^0.0.0",
"@aws-prototyping-sdk/pipeline": "^0.0.0",
"@types/jest": "^27",
"@types/lodash.clonedeep": "^4.5.7",
"@types/lodash.isempty": "^4.4.7",
Expand Down
2 changes: 1 addition & 1 deletion packages/cdk-graph/test/__fixtures__/apps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ export class FixtureStack extends Stack {
});

const vpc = new ec2.Vpc(this, "VPC", {
cidr: "10.0.0.0/16",
ipAddresses: ec2.IpAddresses.cidr("10.0.0.0/16"),
natGateways: 1,
maxAzs: 3,
subnetConfiguration: [
Expand Down
35 changes: 35 additions & 0 deletions packages/cdk-graph/test/__fixtures__/pdk-integ.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*! Copyright [Amazon.com](http://amazon.com/), Inc. or its affiliates. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0 */
import { PDKNagApp } from "@aws-prototyping-sdk/pdk-nag";
import { PDKPipeline } from "@aws-prototyping-sdk/pipeline";
import { AppProps, Stack } from "aws-cdk-lib";
import { ENVIRONMENTS, TestStage } from "./apps";

export interface PDKIntegAppProps {
outdir: string;
}

export class PDKPipelineIntegApp extends PDKNagApp {
constructor(props: PDKIntegAppProps) {
super({ outdir: props.outdir });

const pipelineStack = new Stack(this, "PipelineStack", {
env: ENVIRONMENTS.DEFAULT,
});
const pipeline = new PDKPipeline(pipelineStack, "Pipeline", {
primarySynthDirectory: props.outdir,
repositoryName: "monorepo",
publishAssetsInParallel: false,
crossAccountKeys: true,
synth: {},
});

const devStage = new TestStage(this, "Dev", { env: ENVIRONMENTS.DEV });
pipeline.addStage(devStage);

const prodStage = new TestStage(this, "Prod", { env: ENVIRONMENTS.PROD });
pipeline.addStage(prodStage);

pipeline.buildPipeline(); // Needed for CDK Nag
}
}
42 changes: 42 additions & 0 deletions packages/cdk-graph/test/cdk-graph/pdk-integ.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*! Copyright [Amazon.com](http://amazon.com/), Inc. or its affiliates. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0 */
import * as fs from "fs-extra";
import * as testUtils from "./test-utils";
import { CdkGraph, Graph } from "../../src";
import { PDKPipelineIntegApp } from "../__fixtures__/pdk-integ";

const makeCdkOutdir = async (name: string) =>
testUtils.makeCdkOutDir("pdk-integ", name);

describe("cdk-graph/pdk-integ", () => {
describe("pipeline", () => {
let outdir: string;
let graphJsonFile: string;
let app: PDKPipelineIntegApp;
let graph: CdkGraph;

beforeAll(async () => {
outdir = await makeCdkOutdir("pipeline");

app = new PDKPipelineIntegApp({ outdir });
graph = new CdkGraph(app);
app.synth();
graphJsonFile = graph.graphContext!.graphJson.filepath;
await graph.report();
});

it("should synthesize graph.json", async () => {
expect(await fs.pathExists(graphJsonFile)).toBe(true);
});

it("should serialize <-> deserialize to same", async () => {
const serializedStore = await fs.readJSON(graphJsonFile, {
encoding: "utf-8",
});
const deserializedStore =
Graph.Store.fromSerializedStore(serializedStore);
const reserializedStore = deserializedStore.serialize();
expect(serializedStore).toEqual(reserializedStore);
});
});
});
2 changes: 2 additions & 0 deletions private/projects/cdk-graph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ export class CdkGraphProject extends PDKProject {
keywords: ["aws", "pdk", "jsii", "projen", "cdk", "graph", "cdk-graph"],
repositoryUrl: "https://github.com/aws/aws-prototyping-sdk",
devDeps: [
"@aws-prototyping-sdk/pdk-nag",
"@aws-prototyping-sdk/pipeline",
"@aws-cdk/cfnspec",
"@types/lodash.clonedeep",
"@types/lodash.isempty",
Expand Down

0 comments on commit 982cff5

Please sign in to comment.