forked from pulumi/examples
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Example: how to unit test a component resource (pulumi#1063)
* Example how to unit test a component resource * Update testing-unit-ts/mocha/bucket_pair.ts Co-authored-by: Piers Karsenbarg <[email protected]>
- Loading branch information
1 parent
1081007
commit f9aeb34
Showing
8 changed files
with
78 additions
and
5 deletions.
There are no files selected for viewing
File renamed without changes.
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,26 @@ | ||
import * as aws from "@pulumi/aws" | ||
import * as pulumi from "@pulumi/pulumi"; | ||
|
||
export class BucketPair extends pulumi.ComponentResource { | ||
|
||
contentBucket: aws.s3.Bucket; | ||
logsBucket: aws.s3.Bucket; | ||
|
||
constructor(contentBucketName: string, logsBucketName: string, opts: any) { | ||
super("pulumi:examples:BucketPair", "BucketPair", {}, opts); | ||
|
||
this.contentBucket = new aws.s3.Bucket("contentBucket", { | ||
bucket: contentBucketName, | ||
}, { parent: this }); | ||
|
||
this.logsBucket = new aws.s3.Bucket("logsBucket", { | ||
bucket: logsBucketName, | ||
}, { parent: this }); | ||
|
||
// Register output properties for this component | ||
this.registerOutputs({ | ||
contentBucket: this.contentBucket, | ||
logsBucket: this.logsBucket | ||
}); | ||
} | ||
} |
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,46 @@ | ||
// Copyright 2016-2020, Pulumi Corporation. All rights reserved. | ||
|
||
import * as pulumi from "@pulumi/pulumi"; | ||
import "mocha"; | ||
import * as assert from 'assert'; | ||
|
||
pulumi.runtime.setMocks({ | ||
newResource: function(args: pulumi.runtime.MockResourceArgs): {id: string, state: any} { | ||
switch (args.type) { | ||
default: | ||
return { | ||
id: args.inputs.name + "_id", | ||
state: { | ||
...args.inputs, | ||
}, | ||
}; | ||
} | ||
}, | ||
call: function(args: pulumi.runtime.MockCallArgs) { | ||
switch (args.token) { | ||
default: | ||
return args; | ||
} | ||
}, | ||
}); | ||
|
||
describe("BucketPair", function() { | ||
let module: typeof import("./bucket_pair"); | ||
|
||
before(async function() { | ||
// It's important to import the program _after_ the mocks are defined. | ||
module = await import("./bucket_pair"); | ||
}); | ||
|
||
describe("constructor", function() { | ||
it("must pass bucket names", function(done) { | ||
const bucketPair = new module.BucketPair('my_content_bucket', 'my_logs_bucket', {}); | ||
const outputs = [bucketPair.contentBucket.bucket, bucketPair.logsBucket.bucket]; | ||
pulumi.all(outputs).apply(([contentBucketName, logsBucketName]) => { | ||
assert.strictEqual(contentBucketName, 'my_content_bucket'); | ||
assert.strictEqual(logsBucketName, 'my_logs_bucket'); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
}); |
File renamed without changes.
File renamed without changes.
File renamed without changes.
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 |
---|---|---|
|
@@ -16,7 +16,9 @@ | |
}, | ||
"files": [ | ||
"index.ts", | ||
"ec2tests.ts" | ||
"ec2tests.ts", | ||
"bucket_pair.ts", | ||
"bucket_pair_test.ts", | ||
] | ||
} | ||
|