-
Notifications
You must be signed in to change notification settings - Fork 67
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add unit tests to aws-python #864
Open
justinvp
wants to merge
1
commit into
master
Choose a base branch
from
justin/tests-aws-python
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,2 +1,5 @@ | ||
*.pyc | ||
__pycache__ | ||
.pytest_cache | ||
venv/ | ||
.venv/ |
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,10 +1,6 @@ | ||
"""An AWS Python Pulumi program""" | ||
|
||
import pulumi | ||
from pulumi_aws import s3 | ||
|
||
# Create an AWS resource (S3 Bucket) | ||
bucket = s3.BucketV2('my-bucket') | ||
import infra | ||
|
||
# Export the name of the bucket | ||
pulumi.export('bucket_name', bucket.id) | ||
# Export the name of the bucket. | ||
pulumi.export("bucket_name", 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,9 @@ | ||
import pulumi | ||
from pulumi_aws import s3 | ||
|
||
# Create an AWS resource (S3 Bucket) with tags. | ||
bucket = 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 |
---|---|---|
@@ -1,2 +1,3 @@ | ||
pulumi>=3.0.0,<4.0.0 | ||
pulumi-aws>=6.0.2,<7.0.0 | ||
pytest |
Empty file.
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,42 @@ | ||
import asyncio | ||
from typing import Awaitable, TypeVar | ||
|
||
import pulumi | ||
|
||
|
||
# Test helper to convert a Pulumi Output to an Awaitable. | ||
# This should only be used in tests. | ||
T = TypeVar("T") | ||
def awaitable(output: pulumi.Output[T]) -> Awaitable[T]: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe |
||
loop = asyncio.get_running_loop() | ||
future = loop.create_future() | ||
output.apply(lambda x: future.set_result(x)) | ||
return future | ||
|
||
|
||
class MyMocks(pulumi.runtime.Mocks): | ||
# Mock calls to create new resources and return a canned response. | ||
def new_resource(self, 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 [args.name + "_id", args.inputs] | ||
|
||
# Mock function calls and return an empty response. | ||
def call(self, args: pulumi.runtime.MockCallArgs): | ||
return {} | ||
|
||
# Put Pulumi in unit-test mode, mocking all calls to cloud-provider APIs. | ||
pulumi.runtime.set_mocks(MyMocks()) | ||
|
||
# Now import the code that creates resources, and then test it. | ||
import infra | ||
|
||
# Example test. To run, uncomment and run `python -m pytest --disable-pytest-warnings`. | ||
# @pulumi.runtime.test | ||
# async def test_bucket_tags(): | ||
# tags = await awaitable(infra.bucket.tags) | ||
# assert tags, "bucket must have tags" | ||
# assert "Name" in tags, "bucket must have a Name tag" |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moves resource creation to a separate module, which is consistent with the change for
aws-typescript
. See #863 (comment).