Skip to content

Commit

Permalink
Merge #11570
Browse files Browse the repository at this point in the history
11570: testing: Allow plugin testing users to define their own plugin sets r=AaronFriel a=AaronFriel

Updating Pulumi YAML to address pulumi/pulumi-yaml#421 and pulumi/pulumi-yaml#422, requires testing against the Docker v4.0.0-alpha.0 schema. That required updating this repo, and using Go workspaces/module replacement to allow the deploytest plugin loader to find the prerelease schema.

This change allows Pulumi YAML to define its own set of required plugins, decoupling the two repos and preventing the catch-22 here.

Because this repo will need to support the new example being authored which will serve as a test of #421 and #422, this also adds Docker v4.0.0-alpha.0 as a schema.

Co-authored-by: Aaron Friel <mayreply@aaronfriel.com>
  • Loading branch information
bors[bot] and AaronFriel committed Dec 7, 2022
2 parents fbaf685 + c891102 commit e812f69
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 28 deletions.
1 change: 1 addition & 0 deletions Makefile
Expand Up @@ -191,6 +191,7 @@ get_schemas: \
schema-eks!0.37.1 \
schema-eks!0.40.0 \
schema-docker!3.1.0 \
schema-docker!4.0.0-alpha.0 \
schema-awsx!1.0.0-beta.5 \
schema-aws-native!0.13.0 \
schema-google-native!0.18.2
Expand Down
79 changes: 51 additions & 28 deletions pkg/codegen/testing/utils/host.go
Expand Up @@ -9,10 +9,15 @@ import (
"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 NewHost(schemaDirectoryPath string) plugin.Host {
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(
Expand All @@ -22,37 +27,55 @@ func NewHost(schemaDirectoryPath string) plugin.Host {
}, deploytest.WithPath(schemaDirectoryPath))
}

var pluginLoaders []*deploytest.PluginLoader

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,
mockProvider("aws", "4.15.0"),
mockProvider("aws", "4.26.0"),
mockProvider("aws", "4.36.0"),
mockProvider("aws", "4.37.1"),
mockProvider("aws", "5.16.2"),
mockProvider("azure", "4.18.0"),
mockProvider("azure-native", "1.28.0"),
mockProvider("azure-native", "1.29.0"),
mockProvider("random", "4.2.0"),
mockProvider("random", "4.3.1"),
mockProvider("kubernetes", "3.7.0"),
mockProvider("kubernetes", "3.7.2"),
mockProvider("eks", "0.37.1"),
mockProvider("google-native", "0.18.2"),
mockProvider("aws-native", "0.13.0"),
mockProvider("docker", "3.1.0"),
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,
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{"kubernetes", "3.7.0"},
SchemaProvider{"kubernetes", "3.7.2"},
SchemaProvider{"eks", "0.37.1"},
SchemaProvider{"google-native", "0.18.2"},
SchemaProvider{"aws-native", "0.13.0"},
SchemaProvider{"docker", "3.1.0"},
// PCL examples in 'testing/test/testdata/transpiled_examples require these versions
mockProvider("aws", "5.4.0"),
mockProvider("azure-native", "1.56.0"),
mockProvider("eks", "0.40.0"),
mockProvider("aws-native", "0.13.0"),
mockProvider("docker", "3.1.0"),
mockProvider("awsx", "1.0.0-beta.5"),
mockProvider("kubernetes", "3.0.0"),
mockProvider("aws", "4.37.1"),

mockProvider("other", "0.1.0"),
mockProvider("synthetic", "1.0.0"),
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"},
)
}

0 comments on commit e812f69

Please sign in to comment.