Update the TypeScript unit testing example with the correct import style
MODIFY
testing-unit-ts/ec2tests.ts
testing-unit-ts/ec2tests.ts
@@ -52,15 +52,18 @@ pulumi.runtime.setMocks({
},
});
+describe("Infrastructure", function() {
+ let infra: typeof import("./index");
+
+ before(async function() {
// It's important to import the program _after_ the mocks are defined.
-import * as infra from "./index";
+ infra = await import("./index");
+ });
-describe("Infrastructure", function() {
- const server = infra.server;
describe("#server", function() {
// check 1: Instances have a Name tag.
it("must have a name tag", function(done) {
- pulumi.all([server.urn, server.tags]).apply(([urn, tags]) => {
+ pulumi.all([infra.server.urn, infra.server.tags]).apply(([urn, tags]) => {
if (!tags || !tags["Name"]) {
done(new Error(`Missing a name tag on server ${urn}`));
} else {
@@ -71,7 +74,7 @@ describe("Infrastructure", function() {
// check 2: Instances must not use an inline userData script.
it("must not use userData (use an AMI instead)", function(done) {
- pulumi.all([server.urn, server.userData]).apply(([urn, userData]) => {
+ pulumi.all([infra.server.urn, infra.server.userData]).apply(([urn, userData]) => {
if (userData) {
done(new Error(`Illegal use of userData on server ${urn}`));
} else {
@@ -81,11 +84,10 @@ describe("Infrastructure", function() {
});
});
- const group = infra.group;
describe("#group", function() {
// check 3: Instances must not have SSH open to the Internet.
it("must not open port 22 (SSH) to the Internet", function(done) {
- pulumi.all([ group.urn, group.ingress ]).apply(([ urn, ingress ]) => {
+ pulumi.all([infra.group.urn, infra.group.ingress]).apply(([ urn, ingress ]) => {
if (ingress.find(rule =>
rule.fromPort === 22 && (rule.cidrBlocks || []).find(block => block === "0.0.0.0/0"))) {
done(new Error(`Illegal SSH port 22 open to the Internet (CIDR 0.0.0.0/0) on group ${urn}`));

Update the TypeScript unit testing example with the correct import style (#931)