Skip to content

Commit 9af2b9c

Browse files
Add preview "e2e" test for a basic RDS module
This uses the db.t4g.large but the test just crashes on the provisioning so that's fun Working preview
1 parent be8f1f3 commit 9af2b9c

File tree

4 files changed

+96
-0
lines changed

4 files changed

+96
-0
lines changed

tests/acc_test.go

+57
Original file line numberDiff line numberDiff line change
@@ -556,6 +556,63 @@ func TestIntegration(t *testing.T) {
556556
}
557557
}
558558

559+
// Some resources take minutes to provision and destroy.
560+
// TestPreview is for such resources, where we only verify that preview works as expected.
561+
func TestPreview(t *testing.T) {
562+
563+
type testCase struct {
564+
name string // Must be same as project folder in testdata/programs/ts
565+
moduleName string
566+
moduleVersion string
567+
moduleNamespace string
568+
previewExpect map[apitype.OpType]int
569+
}
570+
571+
testcases := []testCase{
572+
{
573+
name: "rdsmod",
574+
moduleName: "terraform-aws-modules/rds/aws",
575+
moduleVersion: "6.10.0",
576+
moduleNamespace: "rds",
577+
previewExpect: map[apitype.OpType]int{
578+
apitype.OpType("create"): 6,
579+
},
580+
},
581+
}
582+
583+
for _, tc := range testcases {
584+
tc := tc
585+
localProviderBinPath := ensureCompiledProvider(t)
586+
skipLocalRunsWithoutCreds(t)
587+
t.Run(tc.name, func(t *testing.T) {
588+
testProgram := filepath.Join("testdata", "programs", "ts", tc.name)
589+
localPath := opttest.LocalProviderPath("terraform-module", filepath.Dir(localProviderBinPath))
590+
previewTest := pulumitest.NewPulumiTest(t, testProgram, localPath)
591+
592+
// Get a prefix for resource names
593+
prefix := generateTestResourcePrefix()
594+
595+
// Set prefix via config
596+
previewTest.SetConfig(t, "prefix", prefix)
597+
598+
// Generate package
599+
pulumiPackageAdd(
600+
t,
601+
previewTest,
602+
localProviderBinPath,
603+
tc.moduleName,
604+
tc.moduleVersion,
605+
tc.moduleNamespace)
606+
607+
// Preview
608+
previewResult := previewTest.Preview(t)
609+
t.Log(previewResult.StdOut)
610+
t.Log(previewResult.StdErr)
611+
autogold.Expect(tc.previewExpect).Equal(t, previewResult.ChangeSummary)
612+
})
613+
}
614+
}
615+
559616
func TestDiffDetail(t *testing.T) {
560617
// Set up a test Bucket
561618
localProviderBinPath := ensureCompiledProvider(t)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
name: rdsmod
2+
runtime: nodejs
3+
description: A minimal TypeScript Pulumi program
4+
config:
5+
pulumi:tags:
6+
value:
7+
pulumi:template: typescript
+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import * as pulumi from "@pulumi/pulumi";
2+
import * as rds from "@pulumi/rds";
3+
4+
5+
const testrds = new rds.Module("test-rds", {
6+
identifier: "test-rds-module",
7+
engine: "mysql",
8+
instance_class: "db.t3.micro",
9+
allocated_storage: 20,
10+
db_name: "testrdsmoduledatabase",
11+
username: "pulumipus",
12+
password: "hawaii",
13+
skip_final_snapshot: true,
14+
deletion_protection: false,
15+
16+
// DB parameter group
17+
family: "mysql8.0",
18+
19+
// DB option group
20+
major_engine_version: "8.0",
21+
})
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"name": "rdsmod",
3+
"devDependencies": {
4+
"@types/node": "^14"
5+
},
6+
"dependencies": {
7+
"@pulumi/pulumi": "^3.0.0",
8+
"@pulumi/terraform-aws-modules": "file:sdks/terraform-aws-modules",
9+
"typescript": "^4.0.0"
10+
}
11+
}

0 commit comments

Comments
 (0)