-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
78 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,4 @@ | ||
import * as pulumi from "@pulumi/pulumi"; | ||
import * as aws from "@pulumi/aws"; | ||
import * as awsx from "@pulumi/awsx"; | ||
import * as infra from "./infra"; | ||
|
||
// Create an AWS resource (S3 Bucket) | ||
const bucket = new aws.s3.BucketV2("my-bucket"); | ||
|
||
// Export the name of the bucket | ||
export const bucketName = bucket.id; | ||
// Export the name of the bucket. | ||
export const bucketName = infra.bucket.id; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import * as pulumi from "@pulumi/pulumi"; | ||
import * as aws from "@pulumi/aws"; | ||
import * as awsx from "@pulumi/awsx"; | ||
|
||
// Create an AWS resource (S3 Bucket) with tags. | ||
export const bucket = new aws.s3.BucketV2("my-bucket", { | ||
tags: { | ||
"Name": "My bucket", | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
/** @type {import('ts-jest').JestConfigWithTsJest} **/ | ||
module.exports = { | ||
testEnvironment: "node", | ||
transform: { | ||
"^.+.tsx?$": ["ts-jest", {}], | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import * as pulumi from "@pulumi/pulumi"; | ||
import "jest"; | ||
|
||
// Test helper to convert a Pulumi Output to a Promise. | ||
// This should only be used in tests. | ||
function promiseOf<T>(output: pulumi.Output<T>): Promise<T> { | ||
return new Promise(resolve => output.apply(resolve)); | ||
} | ||
|
||
describe("infrastructure", () => { | ||
// Define the infra variable as a type whose shape matches the that of the | ||
// to-be-defined infra module. | ||
let infra: typeof import("../infra"); | ||
|
||
beforeAll(() => { | ||
// Put Pulumi in unit-test mode, mocking all calls to cloud-provider APIs. | ||
pulumi.runtime.setMocks({ | ||
// Mock calls to create new resources and return a canned response. | ||
newResource: (args: pulumi.runtime.MockResourceArgs) => { | ||
// Here, we're returning a same-shaped object for all resource types. | ||
// We could, however, use the arguments passed into this function to | ||
// customize the mocked-out properties of a particular resource. | ||
// See the unit-testing docs for details: | ||
// https://www.pulumi.com/docs/iac/concepts/testing/unit/ | ||
return { | ||
id: `${args.name}-id`, | ||
state: args.inputs, | ||
}; | ||
}, | ||
|
||
// Mock function calls and return an empty response. | ||
call: (args: pulumi.runtime.MockCallArgs) => { | ||
return {}; | ||
}, | ||
}); | ||
}); | ||
|
||
beforeEach(async () => { | ||
// Dynamically import the infra module. | ||
infra = await import("../infra"); | ||
}); | ||
|
||
// Example test. To run, uncomment and run `npm test`. | ||
// describe("bucket", () => { | ||
// it("must have a name tag", async () => { | ||
// const tags = await promiseOf(infra.bucket.tags); | ||
// expect(tags).toBeDefined(); | ||
// expect(tags).toHaveProperty("Name"); | ||
// }); | ||
// }); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters