Skip to content

Commit

Permalink
chore: test simple api workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielMSchmidt committed Feb 18, 2022
1 parent a7a3d86 commit cf59062
Show file tree
Hide file tree
Showing 3 changed files with 192 additions and 53 deletions.
79 changes: 73 additions & 6 deletions test/typescript/multiple-stacks/__snapshots__/test.ts.snap
Original file line number Diff line number Diff line change
@@ -1,6 +1,46 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`full integration test synth 1`] = `
exports[`multiple stacks API-driven workflow deploy a stack 1`] = `
Array [
"synthing",
"synthed",
"diffing",
"diffed",
"deploying",
"deploy update",
"deploy update",
"deploy update",
"deploy update",
"deploy update",
"deployed",
]
`;

exports[`multiple stacks API-driven workflow destoy a stack 1`] = `
Array [
"synthing",
"synthed",
"diffing",
"diffed",
"destroying",
"deploy update",
"deploy update",
"deploy update",
"deploy update",
"deploy update",
"deploy update",
"destroyed",
]
`;

exports[`multiple stacks API-driven workflow get outputs for a stack 1`] = `
Array [
"synthing",
"synthed",
]
`;

exports[`multiple stacks CLI-driven workflow synth 1`] = `
"{
\\"//\\": {
\\"metadata\\": {
Expand All @@ -13,7 +53,16 @@ exports[`full integration test synth 1`] = `
\\"stackName\\": \\"first\\",
\\"version\\": \\"stubbed\\"
},
\\"outputs\\": {}
\\"outputs\\": {
\\"first\\": {
\\"output\\": \\"output\\"
}
}
},
\\"output\\": {
\\"output\\": {
\\"value\\": \\"first\\"
}
},
\\"provider\\": {
\\"null\\": [
Expand Down Expand Up @@ -55,7 +104,7 @@ exports[`full integration test synth 1`] = `
}"
`;

exports[`full integration test synth 2`] = `
exports[`multiple stacks CLI-driven workflow synth 2`] = `
"{
\\"//\\": {
\\"metadata\\": {
Expand All @@ -68,7 +117,16 @@ exports[`full integration test synth 2`] = `
\\"stackName\\": \\"second\\",
\\"version\\": \\"stubbed\\"
},
\\"outputs\\": {}
\\"outputs\\": {
\\"second\\": {
\\"output\\": \\"output\\"
}
}
},
\\"output\\": {
\\"output\\": {
\\"value\\": \\"second\\"
}
},
\\"provider\\": {
\\"null\\": [
Expand Down Expand Up @@ -110,7 +168,7 @@ exports[`full integration test synth 2`] = `
}"
`;

exports[`full integration test synth with json output 1`] = `
exports[`multiple stacks CLI-driven workflow synth with json output 1`] = `
"{
\\"//\\": {
\\"metadata\\": {
Expand All @@ -123,7 +181,16 @@ exports[`full integration test synth with json output 1`] = `
\\"stackName\\": \\"first\\",
\\"version\\": \\"stubbed\\"
},
\\"outputs\\": {}
\\"outputs\\": {
\\"first\\": {
\\"output\\": \\"output\\"
}
}
},
\\"output\\": {
\\"output\\": {
\\"value\\": \\"first\\"
}
},
\\"provider\\": {
\\"null\\": [
Expand Down
13 changes: 12 additions & 1 deletion test/typescript/multiple-stacks/main.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import { Construct } from "constructs";
import { App, TerraformStack, Testing, LocalBackend } from "cdktf";
import {
App,
TerraformStack,
Testing,
LocalBackend,
TerraformOutput,
} from "cdktf";
import * as NullProvider from "./.gen/providers/null";

export class HelloTerra extends TerraformStack {
Expand All @@ -19,6 +25,11 @@ export class HelloTerra extends TerraformStack {
},
},
]);

new TerraformOutput(this, "output", {
staticId: true,
value: id,
});
}
}

Expand Down
153 changes: 107 additions & 46 deletions test/typescript/multiple-stacks/test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { TestDriver, onPosix, onWindows } from "../../test-helper";
import { CdktfProject } from "../../../packages/cdktf-cli/lib/index";

describe("multiple stacks", () => {
let driver: TestDriver;
Expand All @@ -21,44 +22,44 @@ describe("multiple stacks", () => {

test("diff", () => {
expect(driver.diff("first")).toMatchInlineSnapshot(`
"Stack: first
Resources
+ NULL_RESOURCE test null_resource.test
"Stack: first
Resources
+ NULL_RESOURCE test null_resource.test
Diff: 1 to create, 0 to update, 0 to delete.
"
`);
Diff: 1 to create, 0 to update, 0 to delete.
"
`);

expect(driver.diff("second")).toMatchInlineSnapshot(`
"Stack: second
Resources
+ NULL_RESOURCE test null_resource.test
"Stack: second
Resources
+ NULL_RESOURCE test null_resource.test
Diff: 1 to create, 0 to update, 0 to delete.
"
`);
Diff: 1 to create, 0 to update, 0 to delete.
"
`);

expect(() => driver.diff()).toThrowError("Found more than one stack");
});

onPosix("list posix", () => {
expect(driver.list()).toMatchInlineSnapshot(`
"Stack name Path
first cdktf.out/stacks/first
second cdktf.out/stacks/second
"
`);
"Stack name Path
first cdktf.out/stacks/first
second cdktf.out/stacks/second
"
`);
});

onWindows("list windows", () => {
expect(driver.list()).toMatchInlineSnapshot(`
"Stack name Path
first cdktf.out\\\\stacks\\\\first
second cdktf.out\\\\stacks\\\\second
"
`);
"Stack name Path
first cdktf.out\\\\stacks\\\\first
second cdktf.out\\\\stacks\\\\second
"
`);
});

// completions for stacks relies on a manifest.json being present
Expand All @@ -78,24 +79,28 @@ describe("multiple stacks", () => {

test("deploy", () => {
expect(driver.deploy("first")).toMatchInlineSnapshot(`
" Deploying Stack: first
Resources
✔ NULL_RESOURCE test null_resource.test
" Deploying Stack: first
Resources
✔ NULL_RESOURCE test null_resource.test
Summary: 1 created, 0 updated, 0 destroyed.
"
`);
Summary: 1 created, 0 updated, 0 destroyed.
Output: output = first
"
`);

expect(driver.deploy("second")).toMatchInlineSnapshot(`
" Deploying Stack: second
Resources
✔ NULL_RESOURCE test null_resource.test
" Deploying Stack: second
Resources
✔ NULL_RESOURCE test null_resource.test
Summary: 1 created, 0 updated, 0 destroyed.
Summary: 1 created, 0 updated, 0 destroyed.
"
`);
Output: output = second
"
`);

expect(() => driver.deploy()).toThrowError(
"Found more than one stack, please specify a target stack. Run cdktf <verb> <stack> with one of these stacks: first, second"
Expand All @@ -104,28 +109,84 @@ describe("multiple stacks", () => {

test("destroy", () => {
expect(driver.destroy("first")).toMatchInlineSnapshot(`
" Destroying Stack: first
Resources
✔ NULL_RESOURCE test null_resource.test
" Destroying Stack: first
Resources
✔ NULL_RESOURCE test null_resource.test
Summary: 1 destroyed.
"
`);
Summary: 1 destroyed.
"
`);

expect(driver.destroy("second")).toMatchInlineSnapshot(`
" Destroying Stack: second
Resources
✔ NULL_RESOURCE test null_resource.test
" Destroying Stack: second
Resources
✔ NULL_RESOURCE test null_resource.test
Summary: 1 destroyed.
"
`);
Summary: 1 destroyed.
"
`);

expect(() => driver.destroy()).toThrowError(
"Found more than one stack, please specify a target stack. Run cdktf <verb> <stack> with one of these stacks: first, second"
);
});
});

describe("API-driven workflow", () => {
test("deploy a stack", async () => {
const events = [];
const project = new CdktfProject({
synthCommand: "npx ts-node main.ts",
targetDir: driver.workingDirectory,
autoApprove: true,
onUpdate: (event) => {
events.push(event);
},
});

await project.deploy("first");
expect(events.map((event) => event.type)).toMatchSnapshot();
});

test("get outputs for a stack", async () => {
const events = [];
const project = new CdktfProject({
synthCommand: "npx ts-node main.ts",
targetDir: driver.workingDirectory,
autoApprove: true,
onUpdate: (event) => {
events.push(event);
},
});

const outputs = await project.fetchOutputs("first");
expect(events.map((event) => event.type)).toMatchSnapshot();
expect(outputs).toMatchInlineSnapshot(`
Object {
"output": Object {
"sensitive": false,
"type": "string",
"value": "first",
},
}
`);
});

test("destoy a stack", async () => {
const events = [];
const project = new CdktfProject({
synthCommand: "npx ts-node main.ts",
targetDir: driver.workingDirectory,
autoApprove: true,
onUpdate: (event) => {
events.push(event);
},
});

await project.destroy("first");
expect(events.map((event) => event.type)).toMatchSnapshot();
});
});
});

0 comments on commit cf59062

Please sign in to comment.