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 a test for provider resources #324

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
8 changes: 8 additions & 0 deletions tests/integration/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,14 @@ func TestValidateResource(t *testing.T) {
{
WantErrors: nil,
},
// Test scenario 12: provider resource.
{
WantErrors: []string{
"[mandatory] random-provider (pulumi:providers:random: foobar)",
"Prohibits creating a random provider named 'foobar'.",
"Cannot create a random provider named 'foobar'.",
},
},
})
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ def large_resource(args: ResourceValidationArgs, report_violation: ReportViolati
if result != expected:
report_violation(f"'longString' had expected length of {expected}, got {result}")

def provider(args: ResourceValidationArgs, report_violation: ReportViolation):
if args.resource_type == "pulumi:providers:random":
if args.name == "foobar":
report_violation("Cannot create a random provider named 'foobar'.")


PolicyPack(
name="validate-resource-test-policy",
Expand Down Expand Up @@ -86,6 +91,11 @@ def large_resource(args: ResourceValidationArgs, report_violation: ReportViolati
name="large-resource",
description="Ensures that large string properties are set properly.",
validate=large_resource,
),
ResourceValidationPolicy(
name="random-provider",
description="Prohibits creating a random provider named 'foobar'.",
validate=provider,
)
],
)
13 changes: 12 additions & 1 deletion tests/integration/validate_resource/policy-pack/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,17 @@ new PolicyPack("validate-resource-test-policy", {
}
}
},
}
},
// Strongly-typed provider.
{
name: "random-provider",
description: "Prohibits creating a random provider named 'foobar'.",
enforcementLevel: "mandatory",
validateResource: validateResourceOfType(random.Provider, (it, args, reportViolation) => {
if (args.name === "foobar") {
reportViolation("Cannot create a random provider named 'foobar'.")
}
}),
},
],
});
6 changes: 6 additions & 0 deletions tests/integration/validate_resource/program/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,10 @@ switch (testScenario) {
// Create a resource with a large string property.
const longString = "a".repeat(5 * 1024 * 1024);
const largeStringResource = new Resource("large-resource", { state: 6, longString })
break;

case 12:
// Create a provider resource named 'foobar'.
new random.Provider("foobar");
break;
}
Loading