github.com/myhau/pulumi/pkg/v3@v3.70.2-0.20221116134521-f2775972e587/codegen/testing/utils/host.go (about)

     1  package utils
     2  
     3  import (
     4  	"fmt"
     5  
     6  	"github.com/blang/semver"
     7  	"github.com/pulumi/pulumi/pkg/v3/resource/deploy/deploytest"
     8  	"github.com/pulumi/pulumi/sdk/v3/go/common/resource/plugin"
     9  	"github.com/pulumi/pulumi/sdk/v3/go/common/tokens"
    10  )
    11  
    12  // NewHost creates a schema-only plugin host, supporting multiple package versions in tests. This
    13  // enables running tests offline. If this host is used to load a plugin, that is, to run a Pulumi
    14  // program, it will panic.
    15  func NewHost(schemaDirectoryPath string) plugin.Host {
    16  	mockProvider := func(name tokens.Package, version string) *deploytest.PluginLoader {
    17  		return deploytest.NewProviderLoader(name, semver.MustParse(version), func() (plugin.Provider, error) {
    18  			panic(fmt.Sprintf(
    19  				"expected plugin loader to use cached schema path, but cache was missed for package %v@%v, "+
    20  					"is an entry in the makefile or setup for this package missing?",
    21  				name, version))
    22  		}, deploytest.WithPath(schemaDirectoryPath))
    23  	}
    24  
    25  	// For the pulumi/pulumi repository, this must be kept in sync with the makefile and/or committed
    26  	// schema files in the given schema directory. This is the minimal set of schemas that must be
    27  	// supplied.
    28  	return deploytest.NewPluginHost(nil, nil, nil,
    29  		mockProvider("aws", "4.15.0"),
    30  		mockProvider("aws", "4.26.0"),
    31  		mockProvider("aws", "4.36.0"),
    32  		mockProvider("aws", "4.37.1"),
    33  		mockProvider("aws", "5.16.2"),
    34  		mockProvider("azure", "4.18.0"),
    35  		mockProvider("azure-native", "1.28.0"),
    36  		mockProvider("azure-native", "1.29.0"),
    37  		mockProvider("random", "4.2.0"),
    38  		mockProvider("random", "4.3.1"),
    39  		mockProvider("kubernetes", "3.7.0"),
    40  		mockProvider("kubernetes", "3.7.2"),
    41  		mockProvider("eks", "0.37.1"),
    42  		mockProvider("google-native", "0.18.2"),
    43  		mockProvider("aws-native", "0.13.0"),
    44  		mockProvider("docker", "3.1.0"),
    45  		// PCL examples in 'testing/test/testdata/transpiled_examples require these versions
    46  		mockProvider("aws", "5.4.0"),
    47  		mockProvider("azure-native", "1.56.0"),
    48  		mockProvider("eks", "0.40.0"),
    49  		mockProvider("aws-native", "0.13.0"),
    50  		mockProvider("docker", "3.1.0"),
    51  		mockProvider("awsx", "1.0.0-beta.5"),
    52  		mockProvider("kubernetes", "3.0.0"),
    53  		mockProvider("aws", "4.37.1"),
    54  
    55  		mockProvider("other", "0.1.0"),
    56  		mockProvider("synthetic", "1.0.0"),
    57  	)
    58  }