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

99 lines
3.8 KiB
Go
Raw 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
}
// 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"},
SchemaProvider{"aws-native", "0.13.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"},
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"},
)
}