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

test: establish a baseline for testing dep propagation #236

Closed
wants to merge 1 commit into from
Closed
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
63 changes: 63 additions & 0 deletions tests/acc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
pt := pulumitest.NewPulumiTest(t, randModProg, localPath)
pt.CopyToTempDir(t)

packageName := "randmod"

Check failure on line 59 in tests/acc_test.go

View workflow job for this annotation

GitHub Actions / lint / lint

string `randmod` has 3 occurrences, make it a constant (goconst)
t.Run("pulumi package add", func(t *testing.T) {
// pulumi package add <provider-path> <randmod-path> <package-name>
pulumiPackageAdd(t, pt, localProviderBinPath, randMod, packageName)
Expand Down Expand Up @@ -1162,6 +1162,69 @@

}

// Test that Pulumi understands dependencies.
func Test_Dependencies(t *testing.T) {
localProviderBinPath := ensureCompiledProvider(t)

// Reuse randmod for this one.
randMod, err := filepath.Abs(filepath.Join("testdata", "modules", "randmod"))
require.NoError(t, err)

// Program written to support the test.
randModProg := filepath.Join("testdata", "programs", "ts", "dep-tester")

localPath := opttest.LocalProviderPath(provider, filepath.Dir(localProviderBinPath))
pt := pulumitest.NewPulumiTest(t, randModProg, localPath)
pt.CopyToTempDir(t)

packageName := "randmod"

// pulumi package add <provider-path> <randmod-path> <package-name>
pulumiPackageAdd(t, pt, localProviderBinPath, randMod, packageName)

upOutput := pt.Up(t)
t.Logf("pulumi up said: %s\n", upOutput.StdOut+upOutput.StdErr)

deploy := pt.ExportStack(t)

t.Logf("DEPLOYMENT: %v", string(deploy.Deployment))

var deployment apitype.DeploymentV3
err = json.Unmarshal(deploy.Deployment, &deployment)
require.NoError(t, err)

for _, r := range deployment.Resources {
if r.URN.Type() == "randmod:index:Module" {
autogold.Expect(map[string]interface{}{}).Equal(t, r.Inputs)
autogold.Expect(map[string]interface{}{"random_priority": 2, "random_seed": map[string]interface{}{
"4dabf18193072939515e22adb298388d": "1b47061264138c4ac30d75fd1eb44270",
"plaintext": `"9"`,
}}).Equal(t, r.Outputs)
autogold.Expect([]urn.URN{}).Equal(t, r.Dependencies)
autogold.Expect(map[resource.PropertyKey][]urn.URN{}).Equal(t, r.PropertyDependencies)
}

if r.URN.Type() == "randmod:index:ModuleState" {
// r.Outputs are too large, ignore for now in this test
autogold.Expect(map[string]interface{}{
"__module": "urn:pulumi:test::ts-dep-tester::randmod:index:Module::myrandmod",
"moduleInputs": map[string]interface{}{
"maxlen": 10,
"randseed": map[string]interface{}{
"4dabf18193072939515e22adb298388d": "1b47061264138c4ac30d75fd1eb44270",
"plaintext": `"9"`,
},
},
}).Equal(t, r.Inputs)
autogold.Expect([]urn.URN{}).Equal(t, r.Dependencies)
autogold.Expect(map[resource.PropertyKey][]urn.URN{
resource.PropertyKey("__module"): {},
resource.PropertyKey("moduleInputs"): {},
}).Equal(t, r.PropertyDependencies)
}
}
}

// runPreviewWithPlanDiff runs a pulumi preview that creates a plan file
// and returns a map of resource diffs for the resources that have changes based on the plan
func runPreviewWithPlanDiff(
Expand Down
5 changes: 5 additions & 0 deletions tests/testdata/programs/ts/dep-tester/Pulumi.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
name: ts-dep-tester
runtime:
name: nodejs
options:
packagemanager: npm
18 changes: 18 additions & 0 deletions tests/testdata/programs/ts/dep-tester/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import * as pulumi from '@pulumi/pulumi';
import * as randmod from "@pulumi/randmod";
import * as random from '@pulumi/random';

const seed = new random.RandomInteger('seed', {
max: 16,
min: 1,
seed: 'the-most-random-seed',
});

// Expect Pulumi to recognize that randmod.Module depends on RandomInteger.
const m = new randmod.Module("myrandmod", {
maxlen: 10,
randseed: pulumi.secret(seed.result.apply(n => String(n))),
});

export const randomPriority = m.random_priority;
export const randomSeed = m.random_seed;
12 changes: 12 additions & 0 deletions tests/testdata/programs/ts/dep-tester/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"name": "ts-dep-tester",
"main": "index.ts",
"devDependencies": {
"@types/node": "^18",
"typescript": "^5.0.0"
},
"dependencies": {
"@pulumi/pulumi": "^3.113.0",
"@pulumi/random": "^4.17.0"
}
}
Loading