Skip to content

Commit

Permalink
Merge #11306 #11313
Browse files Browse the repository at this point in the history
11306: [sdk/nodejs] Cleanup use of `asyncTest` and `assertAsyncThrows` r=justinvp a=justinvp

The `asyncTest` and `assertAsyncThrows` helpers were necessary when originally written, but are no longer needed as Mocha has built-in support for testing async functions that return promises, and Node's `assert.rejects` can be used to assert whether a promise has been rejected.

11313: Regenerate .pyi files, sort diffs on proto cksum r=iwahbe a=iwahbe

Regenerate the .pyi files as left from #11095. 

It's unclear to me why this didn't happen in the initial PR. The only thing I can think of is that .checksum.txt was manually edited. 

Co-authored-by: Justin Van Patten <jvp@justinvp.com>
Co-authored-by: Ian Wahbe <ian@wahbe.com>
  • Loading branch information
3 people committed Nov 10, 2022
3 parents 9df03f5 + 1fca4e9 + eecbe29 commit 42cb2c8
Show file tree
Hide file tree
Showing 15 changed files with 336 additions and 333 deletions.
10 changes: 6 additions & 4 deletions Makefile
Expand Up @@ -33,22 +33,24 @@ ensure: .ensure.phony go.ensure $(SUB_PROJECTS:%=%_ensure)
@touch .ensure.phony

.PHONY: build-proto
PROTO_FILES := $(sort $(shell find proto/ -type f -name '*.proto') proto/generate.sh proto/build-container/Dockerfile $(wildcard proto/build-container/scripts/*))
PROTO_FILES := $(sort $(shell find proto -type f -name '*.proto') proto/generate.sh proto/build-container/Dockerfile $(wildcard proto/build-container/scripts/*))
PROTO_CKSUM = cksum ${PROTO_FILES} | sort --key=3
build-proto:
@printf "Protobuffer interfaces are ....... "
@if [ "$$(cat proto/.checksum.txt)" = "$$(cksum $(PROTO_FILES))" ]; then \
@if [ "$$(cat proto/.checksum.txt)" = "`${PROTO_CKSUM}`" ]; then \
printf "\033[0;32mup to date\033[0m\n"; \
else \
printf "\033[0;34mout of date: REBUILDING\033[0m\n"; \
cd proto && ./generate.sh || exit 1; \
cd ../ && cksum $(PROTO_FILES) > proto/.checksum.txt; \
cd ../ && ${PROTO_CKSUM} > proto/.checksum.txt; \
printf "\033[0;34mProtobuffer interfaces have been \033[0;32mREBUILT\033[0m\n"; \
fi

.PHONY: check-proto
check-proto:
@if [ "$$(cat proto/.checksum.txt)" != "$$(cksum $(PROTO_FILES))" ]; then \
@if [ "$$(cat proto/.checksum.txt)" != "`${PROTO_CKSUM}`" ]; then \
echo "Protobuff checksum doesn't match. Run \`make build-proto\` to rebuild."; \
${PROTO_CKSUM} | diff - proto/.checksum.txt; \
exit 1; \
fi

Expand Down
5 changes: 2 additions & 3 deletions sdk/nodejs/tests/automation/cmd.spec.ts
Expand Up @@ -14,10 +14,9 @@

import * as assert from "assert";
import { runPulumiCmd } from "../../automation";
import { asyncTest } from "../util";

describe("automation/cmd", () => {
it("calls onOutput when provided to runPulumiCmd", asyncTest(async () => {
it("calls onOutput when provided to runPulumiCmd", async () => {
let output = "";
let numCalls = 0;
await runPulumiCmd(["--help"], ".", {}, (data: string) => {
Expand All @@ -27,5 +26,5 @@ describe("automation/cmd", () => {
assert.ok(numCalls > 0, `expected numCalls > 0, got ${numCalls}`);
assert.match(output, new RegExp("Usage[:]"));
assert.match(output, new RegExp("[-][-]verbose"));
}));
});
});
93 changes: 46 additions & 47 deletions sdk/nodejs/tests/automation/localWorkspace.spec.ts
Expand Up @@ -27,14 +27,13 @@ import {
parseAndValidatePulumiVersion,
} from "../../automation";
import { Config, output } from "../../index";
import { asyncTest } from "../util";
import { getTestOrg, getTestSuffix } from "./util";

const versionRegex = /(\d+\.)(\d+\.)(\d+)(-.*)?/;
const userAgent = "pulumi/pulumi/test";

describe("LocalWorkspace", () => {
it(`projectSettings from yaml/yml/json`, asyncTest(async () => {
it(`projectSettings from yaml/yml/json`, async () => {
for (const ext of ["yaml", "yml", "json"]) {
const ws = await LocalWorkspace.create({ workDir: upath.joinSafe(__dirname, "data", ext) });
const settings = await ws.projectSettings();
Expand All @@ -43,28 +42,28 @@ describe("LocalWorkspace", () => {
assert(settings.description, "A minimal Go Pulumi program");

}
}));
});

it(`stackSettings from yaml/yml/json`, asyncTest(async () => {
it(`stackSettings from yaml/yml/json`, async () => {
for (const ext of ["yaml", "yml", "json"]) {
const ws = await LocalWorkspace.create({ workDir: upath.joinSafe(__dirname, "data", ext) });
const settings = await ws.stackSettings("dev");
assert.strictEqual(settings.secretsProvider, "abc");
assert.strictEqual(settings.config!["plain"], "plain");
assert.strictEqual(settings.config!["secure"].secure, "secret");
}
}));
});

it(`adds/removes/lists plugins successfully`, asyncTest(async () => {
it(`adds/removes/lists plugins successfully`, async () => {
const ws = await LocalWorkspace.create({});
await ws.installPlugin("aws", "v3.0.0");
// See https://github.com/pulumi/pulumi/issues/11013 for why this is disabled
//await ws.installPluginFromServer("scaleway", "v1.2.0", "github://api.github.com/lbrlabs");
await ws.removePlugin("aws", "3.0.0");
await ws.listPlugins();
}));
});

it(`create/select/remove LocalWorkspace stack`, asyncTest(async () => {
it(`create/select/remove LocalWorkspace stack`, async () => {
const projectName = "node_test";
const projectSettings: ProjectSettings = {
name: projectName,
Expand All @@ -75,9 +74,9 @@ describe("LocalWorkspace", () => {
await ws.createStack(stackName);
await ws.selectStack(stackName);
await ws.removeStack(stackName);
}));
});

it(`create/select/createOrSelect Stack`, asyncTest(async () => {
it(`create/select/createOrSelect Stack`, async () => {
const projectName = "node_test";
const projectSettings: ProjectSettings = {
name: projectName,
Expand All @@ -89,8 +88,8 @@ describe("LocalWorkspace", () => {
await Stack.select(stackName, ws);
await Stack.createOrSelect(stackName, ws);
await ws.removeStack(stackName);
}));
it(`Config`, asyncTest(async () => {
});
it(`Config`, async () => {
const projectName = "node_test";
const projectSettings: ProjectSettings = {
name: projectName,
Expand Down Expand Up @@ -133,8 +132,8 @@ describe("LocalWorkspace", () => {
assert.strictEqual(Object.keys(values).length, 2, "expected stack config to have 2 values");

await ws.removeStack(stackName);
}));
it(`config_flag_like`, asyncTest(async () => {
});
it(`config_flag_like`, async () => {
const projectName = "config_flag_like";
const projectSettings: ProjectSettings = {
name: projectName,
Expand All @@ -159,8 +158,8 @@ describe("LocalWorkspace", () => {
assert.strictEqual(values2["config_flag_like:key"].secret, false);
assert.strictEqual(values2["config_flag_like:secret-key"].value, "-value2");
assert.strictEqual(values2["config_flag_like:secret-key"].secret, true);
}));
it(`nested_config`, asyncTest(async () => {
});
it(`nested_config`, async () => {
if (getTestOrg() !== "pulumi-test") {
return;
}
Expand All @@ -184,8 +183,8 @@ describe("LocalWorkspace", () => {
const list = await stack.getConfig("myList");
assert.strictEqual(list.secret, false);
assert.strictEqual(list.value, "[\"one\",\"two\",\"three\"]");
}));
it(`can list stacks and currently selected stack`, asyncTest(async () => {
});
it(`can list stacks and currently selected stack`, async () => {
const projectName = `node_list_test${getTestSuffix()}`;
const projectSettings: ProjectSettings = {
name: projectName,
Expand All @@ -207,8 +206,8 @@ describe("LocalWorkspace", () => {
for (const name of stackNames) {
await ws.removeStack(name);
}
}));
it(`stack status methods`, asyncTest(async () => {
});
it(`stack status methods`, async () => {
const projectName = "node_test";
const projectSettings: ProjectSettings = {
name: projectName,
Expand All @@ -222,9 +221,9 @@ describe("LocalWorkspace", () => {
const info = await stack.info();
assert.strictEqual(typeof (info), "undefined");
await ws.removeStack(stackName);
}));
});
// TODO[pulumi/pulumi#8220] understand why this test was flaky
xit(`runs through the stack lifecycle with a local program`, asyncTest(async () => {
xit(`runs through the stack lifecycle with a local program`, async () => {
const stackName = fullyQualifiedStackName(getTestOrg(), "testproj", `int_test${getTestSuffix()}`);
const workDir = upath.joinSafe(__dirname, "data", "testproj");
const stack = await LocalWorkspace.createStack({ stackName, workDir });
Expand Down Expand Up @@ -262,8 +261,8 @@ describe("LocalWorkspace", () => {
assert.strictEqual(destroyRes.summary.result, "succeeded");

await stack.workspace.removeStack(stackName);
}));
it(`runs through the stack lifecycle with an inline program`, asyncTest(async () => {
});
it(`runs through the stack lifecycle with an inline program`, async () => {
const program = async () => {
const config = new Config();
return {
Expand Down Expand Up @@ -309,8 +308,8 @@ describe("LocalWorkspace", () => {
assert.strictEqual(destroyRes.summary.result, "succeeded");

await stack.workspace.removeStack(stackName);
}));
it(`successfully initializes multiple stacks`, asyncTest(async () => {
});
it(`successfully initializes multiple stacks`, async () => {
const program = async () => {
const config = new Config();
return {
Expand All @@ -323,8 +322,8 @@ describe("LocalWorkspace", () => {
const stackNames = Array.from(Array(10).keys()).map(_ => fullyQualifiedStackName(getTestOrg(), projectName, `int_test${getTestSuffix()}`));
const stacks = await Promise.all(stackNames.map(async stackName => LocalWorkspace.createStack({ stackName, projectName, program })));
await stacks.map(stack => stack.workspace.removeStack(stack.name));
}));
it(`runs through the stack lifecycle with multiple inline programs in parallel`, asyncTest(async () => {
});
it(`runs through the stack lifecycle with multiple inline programs in parallel`, async () => {
const program = async () => {
const config = new Config();
return {
Expand Down Expand Up @@ -375,8 +374,8 @@ describe("LocalWorkspace", () => {
};

await Promise.all(stackNames.map(async stackName => await testStackLifetime(stackName)));
}));
it(`handles events`, asyncTest(async () => {
});
it(`handles events`, async () => {
const program = async () => {
const config = new Config();
return {
Expand Down Expand Up @@ -435,10 +434,10 @@ describe("LocalWorkspace", () => {
assert.strictEqual(destroyRes.summary.result, "succeeded");

await stack.workspace.removeStack(stackName);
}));
});
// TODO[pulumi/pulumi#7127]: Re-enabled the warning.
// Temporarily skipping test until we've re-enabled the warning.
it.skip(`has secret config warnings`, asyncTest(async () => {
it.skip(`has secret config warnings`, async () => {
const program = async () => {
const config = new Config();

Expand Down Expand Up @@ -597,8 +596,8 @@ describe("LocalWorkspace", () => {
validate(events);

await stack.workspace.removeStack(stackName);
}));
it(`imports and exports stacks`, asyncTest(async () => {
});
it(`imports and exports stacks`, async () => {
const program = async () => {
const config = new Config();
return {
Expand Down Expand Up @@ -631,9 +630,9 @@ describe("LocalWorkspace", () => {
assert.strictEqual(destroyRes.summary.result, "succeeded");
await stack.workspace.removeStack(stackName);
}
}));
});
// TODO[pulumi/pulumi#8061] flaky test
xit(`supports stack outputs`, asyncTest(async () => {
xit(`supports stack outputs`, async () => {
const program = async () => {
const config = new Config();
return {
Expand Down Expand Up @@ -683,8 +682,8 @@ describe("LocalWorkspace", () => {
} finally {
await stack.workspace.removeStack(stackName);
}
}));
it(`runs an inline program that rejects a promise and exits gracefully`, asyncTest(async () => {
});
it(`runs an inline program that rejects a promise and exits gracefully`, async () => {
const program = async () => {
Promise.reject(new Error());
return {};
Expand All @@ -702,8 +701,8 @@ describe("LocalWorkspace", () => {
assert.strictEqual(destroyRes.summary.result, "succeeded");

await stack.workspace.removeStack(stackName);
}));
it(`detects inline programs with side by side pulumi and throws an error`, asyncTest(async () => {
});
it(`detects inline programs with side by side pulumi and throws an error`, async () => {

const program = async () => {
// clear pulumi/pulumi from require cache
Expand Down Expand Up @@ -734,13 +733,13 @@ describe("LocalWorkspace", () => {
assert.strictEqual(destroyRes.summary.result, "succeeded");

await stack.workspace.removeStack(stackName);
}));
it(`sets pulumi version`, asyncTest(async () => {
});
it(`sets pulumi version`, async () => {
const ws = await LocalWorkspace.create({});
assert(ws.pulumiVersion);
assert.strictEqual(versionRegex.test(ws.pulumiVersion), true);
}));
it(`respects existing project settings`, asyncTest(async () => {
});
it(`respects existing project settings`, async () => {
const projectName = "correct_project";
const stackName = fullyQualifiedStackName(getTestOrg(), projectName, `int_test${getTestSuffix()}`);
const stack = await LocalWorkspace.createStack(
Expand All @@ -752,8 +751,8 @@ describe("LocalWorkspace", () => {
// the description check is enough to verify that the stack wasn't overwritten
assert.strictEqual(projectSettings.description, "This is a description");
await stack.workspace.removeStack(stackName);
}));
it(`correctly sets config on multiple stacks concurrently`, asyncTest(async () => {
});
it(`correctly sets config on multiple stacks concurrently`, async () => {
const dones = [];
const stacks = ["dev", "dev2", "dev3", "dev4", "dev5"];
const workDir = upath.joinSafe(__dirname, "data", "tcfg");
Expand Down Expand Up @@ -791,7 +790,7 @@ describe("LocalWorkspace", () => {
assert.strictEqual(Object.keys(config).length, 20);
await stack.workspace.removeStack(stacks[i]);
}
}));
});
});

const MAJOR = /Major version mismatch./;
Expand Down
9 changes: 4 additions & 5 deletions sdk/nodejs/tests/iterable.spec.ts
Expand Up @@ -15,10 +15,9 @@
import * as assert from "assert";
import * as iterable from "../iterable";
import { Output } from "../output";
import { asyncTest } from "./util";

describe("iterable", () => {
it("toMap does its job", asyncTest(async () => {
it("toMap does its job", async () => {
interface Instance {
id: Output<string>;
privateIp: Output<string>;
Expand All @@ -34,8 +33,8 @@ describe("iterable", () => {
assert.strictEqual(isKnown, true);
const value = await result.promise();
assert.deepStrictEqual(value, { "i-1234": "192.168.1.2", "i-5678": "192.168.1.5" });
}));
it("groupBy does its job", asyncTest(async () => {
});
it("groupBy does its job", async () => {
interface Instance {
id: Output<string>;
availabilityZone: Output<string>;
Expand All @@ -52,5 +51,5 @@ describe("iterable", () => {
assert.strictEqual(isKnown, true);
const value = await result.promise();
assert.deepStrictEqual(value, { "us-east-1a": ["i-1234", "i-5678"], "us-west-2c": ["i-1538"] });
}));
});
});

0 comments on commit 42cb2c8

Please sign in to comment.