-
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-csharp #867
Open
justinvp
wants to merge
1
commit into
master
Choose a base branch
from
justin/tests-aws-csharp
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
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,65 @@ | ||
using System.Collections.Generic; | ||
using System.Collections.Immutable; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using Pulumi; | ||
using Pulumi.Aws.S3; | ||
using Pulumi.Testing; | ||
using Xunit; | ||
|
||
public static class TestingExtensions | ||
{ | ||
// Test helper to convert a Pulumi Output to a Task. | ||
// This should only be used in tests. | ||
public static Task<T> GetValueAsync<T>(this Output<T> output) | ||
=> Pulumi.Utilities.OutputUtilities.GetValueAsync(output); | ||
} | ||
|
||
class Mocks : IMocks | ||
{ | ||
// Mock calls to create new resources and return a canned response. | ||
public Task<(string? id, object state)> NewResourceAsync(MockResourceArgs args) | ||
{ | ||
// 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 Task.FromResult<(string?, object)>(($"{args.Name}_id", (object)args.Inputs)); | ||
} | ||
|
||
// Mock function calls and return an empty response. | ||
public Task<object> CallAsync(MockCallArgs args) | ||
{ | ||
return Task.FromResult((object)ImmutableDictionary<string, object>.Empty); | ||
} | ||
} | ||
|
||
public class InfraTests | ||
{ | ||
class TestStack : Stack | ||
{ | ||
public TestStack() | ||
{ | ||
Outputs = Deploy.Infra(); | ||
} | ||
|
||
public Dictionary<string, object?> Outputs { get; set; } | ||
} | ||
|
||
private static Task<ImmutableArray<Resource>> TestAsync() | ||
=> Deployment.TestAsync<TestStack>(new Mocks(), new TestOptions { IsPreview = false }); | ||
|
||
|
||
// Example test. To run, uncomment and run `dotnet test` from the tests directory. | ||
// [Fact] | ||
// public async Task TestBucketTags() | ||
// { | ||
// var resources = await TestAsync(); | ||
// var bucket = resources.OfType<BucketV2>().Single(); | ||
|
||
// var tags = await bucket.Tags.GetValueAsync(); | ||
// Assert.NotNull(tags); | ||
// Assert.Contains("Name", tags); | ||
// } | ||
} |
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,20 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net8.0</TargetFramework> | ||
<Nullable>enable</Nullable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\${PROJECT}.csproj" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Pulumi" Version="3.*" /> | ||
<PackageReference Include="Pulumi.Aws" Version="6.*" /> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.12.0" /> | ||
<PackageReference Include="xunit.v3" Version="0.7.0-pre.15" /> | ||
<PackageReference Include="xunit.runner.visualstudio" Version="3.0.0-pre.49" /> | ||
</ItemGroup> | ||
|
||
</Project> |
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.
The more idiomatic thing to do would be to have the program and test projects SxS:
But we can't easily do that from a template. If we structured the template like this, you wouldn't be able to run
pulumi up
afterpulumi new
because the program would live in a subdirectory. You'd have tocd
into the program's subdirectory first.I think we want to keep it such that you can run
pulumi up
immediately afterpulumi new
, without having to change directories. So we nest the test project:To do so, we have to exclude the source files in the nested project here.
We have a similar issue with parameterized providers, where
pulumi package add
generates the sdks in asdks
subdirectory, and we ask users to add<DefaultItemExcludes>
for that. For that reason, I've included excludes for bothsdks/
andtests/
by default.