pulumi/pkg/codegen/testing/utils/host.go

105 lines
4.0 KiB
Go
Raw Permalink Normal View History

package utils
import (
"fmt"
"github.com/blang/semver"
"github.com/pulumi/pulumi/pkg/v3/resource/deploy/deploytest"
"github.com/pulumi/pulumi/sdk/v3/go/common/resource/plugin"
"github.com/pulumi/pulumi/sdk/v3/go/common/slice"
"github.com/pulumi/pulumi/sdk/v3/go/common/tokens"
)
type SchemaProvider struct {
name string
version string
}
[go/program-gen] Implement importPathPattern in Go language options to override emitted paths in generated Go programs (#16267) # Description Partially addressing https://github.com/pulumi/pulumi-azure-native/issues/3308 Implementing a new go language option called `importPathPattern` which can be used to override how the base import path and modules are concatenated to create imports in generated Go programs. By convention this used to be `{baseImportPath}/{module}` which has worked for all of our providers. However, azure-native v2 has introduced a new import scheme where the convention above causes incorrect import paths to be generated. This is where `importPathPattern` comes into play and allows for a different convention. In the case the of azure-native v2, the pattern _must_ be `github.com/pulumi/pulumi-azure-native-sdk/{module}/v2`. This PR implements `importPathPattern` and tests it using a squashed down azure-native v2 schema containing only contents from the `eventgrid` module. This schema sets the option like this: ```json "importPathPattern": "github.com/pulumi/pulumi-azure-native-sdk/{module}/v2" ``` This schema also modifies `packageImportAliases` from the current azure-native v2 schema to exclude /v2 before the module path (see the file below). This change is needed in the actual azure-native v2 provider cc @danielrbradley and it is the second part of fully fixing https://github.com/pulumi/pulumi-azure-native/issues/3308 > We cannot just use `{baseImportPath}/{module}` because the base import path for azure-native v2 has a suffix v2 (it's required) Also implemented a small feature in ProgramTest to allow overriding the used plugin host for the specific program test, this is because I wanted to test the program against the simplified azure-native v2 schema without changing how other test load the previous azure-native v1.x schemas (I tested that without this, binding programs fails) ## Checklist - [ ] I have run `make tidy` to update any new dependencies - [x] I have run `make lint` to verify my code passes the lint check - [x] I have formatted my code using `gofumpt` <!--- Please provide details if the checkbox below is to be left unchecked. --> - [ ] I have added tests that prove my fix is effective or that my feature works <!--- User-facing changes require a CHANGELOG entry. --> - [x] I have run `make changelog` and committed the `changelog/pending/<file>` documenting my change <!-- If the change(s) in this PR is a modification of an existing call to the Pulumi Cloud, then the service should honor older versions of the CLI where this change would not exist. You must then bump the API version in /pkg/backend/httpstate/client/api.go, as well as add it to the service. --> - [ ] Yes, there are changes in this PR that warrants bumping the Pulumi Cloud API version <!-- @Pulumi employees: If yes, you must submit corresponding changes in the service repo. -->
2024-05-30 19:51:12 +00:00
func NewSchemaProvider(name, version string) SchemaProvider {
return SchemaProvider{name, version}
}
// NewHost creates a schema-only plugin host, supporting multiple package versions in tests. This
// enables running tests offline. If this host is used to load a plugin, that is, to run a Pulumi
// program, it will panic.
func NewHostWithProviders(schemaDirectoryPath string, providers ...SchemaProvider) plugin.Host {
mockProvider := func(name tokens.Package, version string) *deploytest.PluginLoader {
return deploytest.NewProviderLoader(name, semver.MustParse(version), func() (plugin.Provider, error) {
panic(fmt.Sprintf(
"expected plugin loader to use cached schema path, but cache was missed for package %v@%v, "+
"is an entry in the makefile or setup for this package missing?",
name, version))
}, deploytest.WithPath(schemaDirectoryPath))
}
pluginLoaders := slice.Prealloc[*deploytest.PluginLoader](len(providers))
for _, v := range providers {
pluginLoaders = append(pluginLoaders, mockProvider(tokens.Package(v.name), v.version))
}
// For the pulumi/pulumi repository, this must be kept in sync with the makefile and/or committed
// schema files in the given schema directory. This is the minimal set of schemas that must be
// supplied.
return deploytest.NewPluginHost(nil, nil, nil,
pluginLoaders...,
)
}
// NewHost creates a schema-only plugin host, supporting multiple package versions in tests. This
// enables running tests offline. If this host is used to load a plugin, that is, to run a Pulumi
// program, it will panic.
func NewHost(schemaDirectoryPath string) plugin.Host {
// For the pulumi/pulumi repository, this must be kept in sync with the makefile and/or committed
// schema files in the given schema directory. This is the minimal set of schemas that must be
// supplied.
return NewHostWithProviders(schemaDirectoryPath,
Support returning plain values from methods (#13592) Support returning plain values from methods. Implements Node, Python and Go support. Remaining: - [x] test receiving unknowns - [x] acceptance tests written and passing locally for Node, Python, Go clients against a Go server - [x] acceptance tests passing in CI - [x] tickets filed for remaining languages - [x] https://github.com/pulumi/pulumi-yaml/issues/499 - [x] https://github.com/pulumi/pulumi-java/issues/1193 - [x] https://github.com/pulumi/pulumi-dotnet/issues/170 Known limitations: - this is technically a breaking change in case there is code out there that already uses methods that return Plain: true - struct-wrapping limitation: the provider for the component resource needs to still wrap the plain-returning Method response with a 1-arg struct; by convention the field is named "res", and this is how it travels through the plumbing - resources cannot return plain values yet - the provider for the component resource cannot have unknown configuration, if it does, the methods will not be called - Per Luke https://github.com/pulumi/pulumi/issues/11520 this might not be supported/realizable yet <!--- Thanks so much for your contribution! If this is your first time contributing, please ensure that you have read the [CONTRIBUTING](https://github.com/pulumi/pulumi/blob/master/CONTRIBUTING.md) documentation. --> # Description <!--- Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. --> Fixes https://github.com/pulumi/pulumi/issues/12709 ## Checklist - [ ] I have run `make tidy` to update any new dependencies - [ ] I have run `make lint` to verify my code passes the lint check - [ ] I have formatted my code using `gofumpt` <!--- Please provide details if the checkbox below is to be left unchecked. --> - [ ] I have added tests that prove my fix is effective or that my feature works <!--- User-facing changes require a CHANGELOG entry. --> - [ ] I have run `make changelog` and committed the `changelog/pending/<file>` documenting my change <!-- If the change(s) in this PR is a modification of an existing call to the Pulumi Cloud, then the service should honor older versions of the CLI where this change would not exist. You must then bump the API version in /pkg/backend/httpstate/client/api.go, as well as add it to the service. --> - [ ] Yes, there are changes in this PR that warrants bumping the Pulumi Cloud API version <!-- @Pulumi employees: If yes, you must submit corresponding changes in the service repo. -->
2023-11-18 06:02:06 +00:00
SchemaProvider{"tls", "4.10.0"},
SchemaProvider{"aws", "4.15.0"},
SchemaProvider{"aws", "4.26.0"},
SchemaProvider{"aws", "4.36.0"},
SchemaProvider{"aws", "4.37.1"},
SchemaProvider{"aws", "5.16.2"},
SchemaProvider{"azure", "4.18.0"},
SchemaProvider{"azure-native", "1.28.0"},
SchemaProvider{"azure-native", "1.29.0"},
SchemaProvider{"random", "4.2.0"},
SchemaProvider{"random", "4.3.1"},
SchemaProvider{"random", "4.11.2"},
SchemaProvider{"kubernetes", "3.7.0"},
SchemaProvider{"kubernetes", "3.7.2"},
SchemaProvider{"eks", "0.37.1"},
SchemaProvider{"google-native", "0.18.2"},
SchemaProvider{"google-native", "0.27.0"},
[program-gen/go,dotnet] Fixes emited code for object expressions assigned to properties of type Any (#15770) # Description Fixes #15769 by specifically handling object expressions that are annotated as `Any` and emitting the correct code. - In case of Go, expression `X` is emitted as `pulumi.Any(X)` where the type name here is `map[string]interface{}`. - In case of C#, we generate `Dictionary<string, object?>` expressions (similar to what we do inside `toJSON` calls) - Updates the test aws-native schema from 0.13.0 to 0.99.0 ## Checklist - [ ] I have run `make tidy` to update any new dependencies - [x] I have run `make lint` to verify my code passes the lint check - [x] I have formatted my code using `gofumpt` <!--- Please provide details if the checkbox below is to be left unchecked. --> - [x] I have added tests that prove my fix is effective or that my feature works <!--- User-facing changes require a CHANGELOG entry. --> - [x] I have run `make changelog` and committed the `changelog/pending/<file>` documenting my change <!-- If the change(s) in this PR is a modification of an existing call to the Pulumi Cloud, then the service should honor older versions of the CLI where this change would not exist. You must then bump the API version in /pkg/backend/httpstate/client/api.go, as well as add it to the service. --> - [ ] Yes, there are changes in this PR that warrants bumping the Pulumi Cloud API version <!-- @Pulumi employees: If yes, you must submit corresponding changes in the service repo. -->
2024-03-24 00:06:57 +00:00
SchemaProvider{"aws-native", "0.99.0"},
SchemaProvider{"docker", "3.1.0"},
SchemaProvider{"std", "1.0.0"},
2022-10-20 20:37:10 +00:00
// PCL examples in 'testing/test/testdata/transpiled_examples require these versions
SchemaProvider{"aws", "5.4.0"},
SchemaProvider{"azure-native", "1.56.0"},
SchemaProvider{"eks", "0.40.0"},
SchemaProvider{"aws-native", "0.13.0"},
SchemaProvider{"docker", "4.0.0-alpha.0"},
SchemaProvider{"awsx", "1.0.0-beta.5"},
SchemaProvider{"kubernetes", "3.0.0"},
SchemaProvider{"aws", "4.37.1"},
SchemaProvider{"other", "0.1.0"},
SchemaProvider{"synthetic", "1.0.0"},
[program-gen/tests] Replace discriminated unions test program with a program from a synthetic schema of basic unions (#15771) # Description This PR replaces the test program `discriminated-unions` with a new program `basic-unions` that uses a synthetic schema that has basic union definitions. The former program was failing compilation with Go because of a **faulty** azure-native SDK (tests using v1.56.0). It didn't generate the extra types for union objects (those with suffix `Args`). Those missing extra types are added in newer versions of azure-native SDK but the shape of the same resource doesn't have unions anymore so we can't just upgrade the version of the azure-native sdk we are testing with. I decided not to depend on a specific azure-native SDK and instead use a synthetic schema with the sole purpose of showing that we can emit correct code for fields assigned to object which are bound to different union cases. The downside here is that we can't compile the example for any language since it is a synthetic schema with no generated SDK (conformance tests in Go would make this possible but we are far away from that 😢) Closes #10834 since the original issue was due to faulty SDK, not program-gen. ## Checklist - [ ] I have run `make tidy` to update any new dependencies - [ ] I have run `make lint` to verify my code passes the lint check - [ ] I have formatted my code using `gofumpt` <!--- Please provide details if the checkbox below is to be left unchecked. --> - [x] I have added tests that prove my fix is effective or that my feature works <!--- User-facing changes require a CHANGELOG entry. --> - [ ] I have run `make changelog` and committed the `changelog/pending/<file>` documenting my change <!-- If the change(s) in this PR is a modification of an existing call to the Pulumi Cloud, then the service should honor older versions of the CLI where this change would not exist. You must then bump the API version in /pkg/backend/httpstate/client/api.go, as well as add it to the service. --> - [ ] Yes, there are changes in this PR that warrants bumping the Pulumi Cloud API version <!-- @Pulumi employees: If yes, you must submit corresponding changes in the service repo. -->
2024-03-28 10:49:27 +00:00
SchemaProvider{"basic-unions", "0.1.0"},
SchemaProvider{"range", "1.0.0"},
SchemaProvider{"lambda", "0.1.0"},
SchemaProvider{"remoteref", "1.0.0"},
SchemaProvider{"splat", "1.0.0"},
SchemaProvider{"snowflake", "0.66.1"},
SchemaProvider{"using-dashes", "1.0.0"},
SchemaProvider{"auto-deploy", "0.0.1"},
SchemaProvider{"localref", "1.0.0"},
SchemaProvider{"enum", "1.0.0"},
SchemaProvider{"plain-properties", "1.0.0"},
SchemaProvider{"recursive", "1.0.0"},
[program-gen] Fix panic when generating programs for MLC packages using external types (#15605) # Description For an MLC package such as `aws-static-website`, it has some types which are referenced from the `aws` package. Program-gen assumes packages are inferred from resources and invokes, not types which caused panics in Go (#15597), dotnet and python (https://github.com/pulumi/pulumi-converter-constructor-syntax/issues/2) This PR fixes those panics. In Go the panic was due to using package name instead of the package reference from the imported type. In dotnet and python was due to assuming no external type references. Now we generate nice code for all these languages. That said, there is still an issue of resolving imports for the packages of these external types. It works in Go, TypeScript doesn't need it but dotnet and python do. That is why the latter are added in `SkipCompile` in the test program. Fixes #15597 Fixes https://github.com/pulumi/pulumi-converter-constructor-syntax/issues/3 Fixes https://github.com/pulumi/pulumi-converter-constructor-syntax/issues/2 ## Checklist - [ ] I have run `make tidy` to update any new dependencies - [x] I have run `make lint` to verify my code passes the lint check - [ ] I have formatted my code using `gofumpt` <!--- Please provide details if the checkbox below is to be left unchecked. --> - [x] I have added tests that prove my fix is effective or that my feature works <!--- User-facing changes require a CHANGELOG entry. --> - [x] I have run `make changelog` and committed the `changelog/pending/<file>` documenting my change <!-- If the change(s) in this PR is a modification of an existing call to the Pulumi Cloud, then the service should honor older versions of the CLI where this change would not exist. You must then bump the API version in /pkg/backend/httpstate/client/api.go, as well as add it to the service. --> - [ ] Yes, there are changes in this PR that warrants bumping the Pulumi Cloud API version <!-- @Pulumi employees: If yes, you must submit corresponding changes in the service repo. -->
2024-03-10 17:23:15 +00:00
SchemaProvider{"aws-static-website", "0.4.0"},
SchemaProvider{"typeddict", "1.0.0"},
)
}