Skip to content
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 basic e2e test for Dotnet #230

Merged
merged 4 commits into from
Mar 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 77 additions & 0 deletions tests/acc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -555,6 +555,83 @@ func TestE2eTs(t *testing.T) {
}
}

func TestE2eDotnet(t *testing.T) {

type testCase struct {
name string // Must be same as project folder in testdata/programs/python
moduleName string
moduleVersion string
moduleNamespace string
previewExpect map[apitype.OpType]int
upExpect map[string]int
deleteExpect map[string]int
diffNoChangesExpect map[apitype.OpType]int
}

testcases := []testCase{
{
name: "s3bucketmod",
moduleName: "terraform-aws-modules/s3-bucket/aws",
moduleVersion: "4.5.0",
moduleNamespace: "bucket",
previewExpect: map[apitype.OpType]int{
apitype.OpType("create"): 5,
},
upExpect: map[string]int{
"create": 5,
},
deleteExpect: map[string]int{
"delete": 5,
},
diffNoChangesExpect: map[apitype.OpType]int{
apitype.OpType("same"): 5,
},
},
}

for _, tc := range testcases {
tc := tc
localProviderBinPath := ensureCompiledProvider(t)
skipLocalRunsWithoutCreds(t)
t.Run(tc.name, func(t *testing.T) {
testProgram := filepath.Join("testdata", "programs", "dotnet", tc.name)
integrationTest := pulumitest.NewPulumiTest(
t,
testProgram,
opttest.LocalProviderPath("terraform-module", filepath.Dir(localProviderBinPath)),
opttest.SkipInstall(),
)

// Get a prefix for resource names
prefix := generateTestResourcePrefix()

// Set prefix via config
integrationTest.SetConfig(t, "prefix", prefix)

// Generate package
pulumiPackageAdd(
t,
integrationTest,
localProviderBinPath,
tc.moduleName,
tc.moduleVersion,
tc.moduleNamespace)

previewResult := integrationTest.Preview(t)
autogold.Expect(tc.previewExpect).Equal(t, previewResult.ChangeSummary)

upResult := integrationTest.Up(t)
autogold.Expect(&tc.upExpect).Equal(t, upResult.Summary.ResourceChanges)

previewResult = integrationTest.Preview(t)
autogold.Expect(tc.diffNoChangesExpect).Equal(t, previewResult.ChangeSummary)

destroyResult := integrationTest.Destroy(t)
autogold.Expect(&tc.deleteExpect).Equal(t, destroyResult.Summary.ResourceChanges)
})
}
}

func TestE2ePython(t *testing.T) {

type testCase struct {
Expand Down
16 changes: 16 additions & 0 deletions tests/testdata/programs/dotnet/s3bucketmod/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using System.Collections.Generic;
using Pulumi;
using Pulumi.Bucket;

return await Deployment.RunAsync(() =>
{
// Add your resources here
// e.g. var resource = new Resource("name", new ResourceArgs { });
var config = new Config();
var prefix = config.Get("prefix") ?? Deployment.Instance.StackName;
var myBucketModule = new Pulumi.Bucket.Module("myBucketModule", new ModuleArgs
{
Bucket = $"{prefix}-test-bucket", // Example argument
// Add other arguments here
});
});
11 changes: 11 additions & 0 deletions tests/testdata/programs/dotnet/s3bucketmod/Pulumi.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
name: s3bucketmod
description: A minimal C# Pulumi program
runtime: dotnet
config:
pulumi:tags:
value:
pulumi:template: csharp
plugins:
providers:
- name: terraform-module
path: /Users/guin/go/src/github.com/pulumi/pulumi-terraform-module-provider/bin
14 changes: 14 additions & 0 deletions tests/testdata/programs/dotnet/s3bucketmod/s3bucketmod.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<DefaultItemExcludes>$(DefaultItemExcludes);sdks/**/*.cs</DefaultItemExcludes>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Pulumi" Version="3.*" />
</ItemGroup>

</Project>
Loading