Documentation
¶
Index ¶
- Variables
- func CheckAllFilesGenerated(t *testing.T, actual, expected map[string][]byte)
- func CopyExtraFiles(t *testing.T, dir, lang string)
- func GeneratePackageFilesFromSchema(schemaPath string, genPackageFunc GenPkgSignature) (map[string][]byte, error)
- func LoadBaseline(dir, lang string) (map[string][]byte, error)
- func LoadFiles(dir, lang string, files []string) (map[string][]byte, error)
- func NoSDKCodegenChecks() bool
- func PathExists(path string) (bool, error)
- func RewriteFilesWhenPulumiAccept(t *testing.T, dir, lang string, actual map[string][]byte) bool
- func RunCommand(t *testing.T, name string, cwd string, exec string, args ...string)
- func RunCommandWithOptions(t *testing.T, opts *integration.ProgramTestOptions, name string, cwd string, ...)
- func TestProgramCodegen(t *testing.T, testcase ProgramCodegenOptions)
- func TestSDKCodegen(t *testing.T, opts *SDKCodegenOptions)
- func TestTypeNameCodegen(t *testing.T, language string, newTypeNameGenerator NewTypeNameGeneratorFunc)
- func ValidateFileEquality(t *testing.T, actual, expected map[string][]byte) bool
- func ValidateFileTransformer(t *testing.T, inputFile string, expectedOutputFile string, ...)
- type CheckProgramOutput
- type CodegenCheck
- type GenPkgSignature
- type GenProgram
- type NewTypeNameGeneratorFunc
- type ProgramCodegenOptions
- type ProgramTest
- type SDKCodegenOptions
- type SDKTest
- type SchemaVersion
- type TypeNameGeneratorFunc
Constants ¶
This section is empty.
Variables ¶
var PulumiPulumiProgramTests = []ProgramTest{ { Directory: "aws-s3-folder", Description: "AWS S3 Folder", ExpectNYIDiags: allProgLanguages.Except("go"), SkipCompile: allProgLanguages.Except("dotnet"), }, { Directory: "aws-eks", Description: "AWS EKS", SkipCompile: codegen.NewStringSet("nodejs"), }, { Directory: "aws-fargate", Description: "AWS Fargate", SkipCompile: codegen.NewStringSet("go"), }, { Directory: "aws-s3-logging", Description: "AWS S3 with logging", SkipCompile: allProgLanguages.Except("python"), }, { Directory: "aws-optionals", Description: "AWS get invoke with nested object constructor that takes an optional string", Skip: allProgLanguages.Except("go"), }, { Directory: "aws-webserver", Description: "AWS Webserver", SkipCompile: codegen.NewStringSet("go"), }, { Directory: "azure-native", Description: "Azure Native", Skip: codegen.NewStringSet("go"), SkipCompile: codegen.NewStringSet("go", "nodejs"), }, { Directory: "azure-sa", Description: "Azure SA", }, { Directory: "kubernetes-operator", Description: "K8s Operator", }, { Directory: "kubernetes-pod", Description: "K8s Pod", SkipCompile: codegen.NewStringSet("go", "nodejs"), }, { Directory: "kubernetes-template", Description: "K8s Template", }, { Directory: "random-pet", Description: "Random Pet", }, { Directory: "aws-resource-options", Description: "Resource Options", SkipCompile: codegen.NewStringSet("go"), }, { Directory: "aws-secret", Description: "Secret", }, { Directory: "functions", Description: "Functions", SkipCompile: codegen.NewStringSet("go", "dotnet"), }, { Directory: "output-funcs-aws", Description: "Output Versioned Functions", }, { Directory: "third-party-package", Description: "Ensuring correct imports for third party packages", SkipCompile: codegen.NewStringSet("nodejs", "dotnet", "go"), }, { Directory: "invalid-go-sprintf", Description: "Regress invalid Go", Skip: codegen.NewStringSet("python", "nodejs", "dotnet"), }, { Directory: "python-resource-names", Description: "Repro for #9357", Skip: codegen.NewStringSet("go", "nodejs", "dotnet"), }, }
var PulumiPulumiSDKTests = []*SDKTest{ { Directory: "naming-collisions", Description: "Schema with types that could potentially produce collisions (go).", }, { Directory: "dash-named-schema", Description: "Simple schema with a two part name (foo-bar)", }, { Directory: "external-resource-schema", Description: "External resource schema", SkipCompileCheck: codegen.NewStringSet(golang), }, { Directory: "nested-module", Description: "Nested module", SkipCompileCheck: codegen.NewStringSet(dotnet), }, { Directory: "nested-module-thirdparty", Description: "Third-party nested module", SkipCompileCheck: codegen.NewStringSet(dotnet), }, { Directory: "plain-schema-gh6957", Description: "Repro for #6957", }, { Directory: "resource-args-python-case-insensitive", Description: "Resource args with same named resource and type case insensitive", }, { Directory: "resource-args-python", Description: "Resource args with same named resource and type", }, { Directory: "simple-enum-schema", Description: "Simple schema with enum types", }, { Directory: "simple-plain-schema", Description: "Simple schema with plain properties", }, { Directory: "simple-plain-schema-with-root-package", Description: "Simple schema with root package set", }, { Directory: "simple-resource-schema", Description: "Simple schema with local resource properties", }, { Directory: "simple-resource-schema-custom-pypackage-name", Description: "Simple schema with local resource properties and custom Python package name", }, { Directory: "simple-methods-schema", Description: "Simple schema with methods", SkipCompileCheck: codegen.NewStringSet(nodejs, golang), }, { Directory: "simple-methods-schema-single-value-returns", Description: "Simple schema with methods that return single values", }, { Directory: "simple-yaml-schema", Description: "Simple schema encoded using YAML", }, { Directory: "provider-config-schema", Description: "Simple provider config schema", SkipCompileCheck: codegen.NewStringSet(dotnet), }, { Directory: "replace-on-change", Description: "Simple use of replaceOnChange in schema", }, { Directory: "resource-property-overlap", Description: "A resource with the same name as its property", SkipCompileCheck: codegen.NewStringSet(dotnet, nodejs), }, { Directory: "hyphen-url", Description: "A resource url with a hyphen in its path", }, { Directory: "output-funcs", Description: "Tests targeting the $fn_output helper code generation feature", }, { Directory: "output-funcs-edgeorder", Description: "Regresses Node compilation issues on a subset of azure-native", SkipCompileCheck: codegen.NewStringSet(golang, python), Skip: codegen.NewStringSet("nodejs/test"), }, { Directory: "output-funcs-tfbridge20", Description: "Similar to output-funcs, but with compatibility: tfbridge20, to simulate pulumi-aws use case", SkipCompileCheck: codegen.NewStringSet(python), }, { Directory: "cyclic-types", Description: "Cyclic object types", }, { Directory: "regress-node-8110", Description: "Test the fix for pulumi/pulumi#8110 nodejs compilation error", Skip: codegen.NewStringSet("go/test", "dotnet/test"), }, { Directory: "dashed-import-schema", Description: "Ensure that we handle all valid go import paths", Skip: codegen.NewStringSet("go/test", "dotnet/test"), }, { Directory: "plain-and-default", Description: "Ensure that a resource with a plain default property works correctly", SkipCompileCheck: codegen.NewStringSet(nodejs), }, { Directory: "plain-object-defaults", Description: "Ensure that object defaults are generated (repro #8132)", }, { Directory: "plain-object-disable-defaults", Description: "Ensure that we can still compile safely when defaults are disabled", }, { Directory: "regress-8403", Description: "Regress pulumi/pulumi#8403", SkipCompileCheck: codegen.NewStringSet(python), }, { Directory: "different-package-name-conflict", Description: "different packages with the same resource", Skip: allLanguages, }, { Directory: "different-enum", Description: "An enum in a different package namespace", Skip: codegen.NewStringSet("dotnet/compile"), }, { Directory: "azure-native-nested-types", Description: "Condensed example of nested collection types from Azure Native", }, { Directory: "regress-go-8664", Description: "Regress pulumi/pulumi#8664 affecting Go", Skip: allLanguages.Except("go/any"), }, { Directory: "other-owned", Description: "CSharp rootNamespaces", Skip: allLanguages.Except("dotnet/any").Except("docs/any"), }, { Directory: "external-node-compatibility", Description: "Ensure external package compatibility modes are used when referencing external types", Skip: allLanguages.Except("nodejs/any"), }, { Directory: "external-go-import-aliases", Description: "Ensure external import aliases are honored, and any local import aliases override them", Skip: allLanguages.Except("go/any"), }, { Directory: "external-python-same-module-name", Description: "Ensure referencing external types/resources with the same module name are referenced correctly", Skip: allLanguages.Except("python/any"), }, { Directory: "internal-dependencies-go", Description: "Emit Go internal dependencies", Skip: allLanguages.Except("go/any"), }, }
Functions ¶
func CheckAllFilesGenerated ¶
CheckAllFilesGenerated ensures that the set of expected and actual files generated are exactly equivalent.
func CopyExtraFiles ¶
Useful for populating code-generated destination `codeDir=$dir/$lang` with extra manually written files such as the unit test files. These files are copied from `$dir/$lang-extras` folder if present.
func GeneratePackageFilesFromSchema ¶
func GeneratePackageFilesFromSchema(schemaPath string, genPackageFunc GenPkgSignature) (map[string][]byte, error)
GeneratePackageFilesFromSchema loads a schema and generates files using the provided GeneratePackage function.
func LoadBaseline ¶
`LoadBaseline` loads the contents of the given baseline directory, by inspecting its `codegen-manifest.json`.
func NoSDKCodegenChecks ¶
func NoSDKCodegenChecks() bool
func PathExists ¶
func RewriteFilesWhenPulumiAccept ¶
If PULUMI_ACCEPT is set, writes out actual output to the expected file set, so we can continue enjoying golden tests without manually modifying the expected output.
func RunCommand ¶
func RunCommandWithOptions ¶
func RunCommandWithOptions( t *testing.T, opts *integration.ProgramTestOptions, name string, cwd string, exec string, args ...string)
func TestProgramCodegen ¶
func TestProgramCodegen( t *testing.T, testcase ProgramCodegenOptions, )
TestProgramCodegen runs the complete set of program code generation tests against a particular language's code generator.
A program code generation test consists of a PCL file (.pp extension) and a set of expected outputs for each language.
The PCL file is the only piece that must be manually authored. Once the schema has been written, the expected outputs can be generated by running `PULUMI_ACCEPT=true go test ./..." from the `pkg/codegen` directory. nolint: revive
func TestSDKCodegen ¶
func TestSDKCodegen(t *testing.T, opts *SDKCodegenOptions)
TestSDKCodegen runs the complete set of SDK code generation tests against a particular language's code generator. It also verifies that the generated code is structurally sound.
The test files live in `pkg/codegen/testing/test/testdata` and are registered in `var sdkTests` in `sdk_driver.go`.
An SDK code generation test files consists of a schema and a set of expected outputs for each language. Each test is structured as a directory that contains that information:
testdata/
my-simple-schema/ # i.e. `simple-enum-schema`
schema.(json|yaml)
go/
python/
nodejs/
dotnet/
...
The schema is the only piece that *must* be manually authored.
Once the schema has been written, the actual codegen outputs can be generated by running the following in `pkg/codegen` directory:
PULUMI_ACCEPT=true go test ./...
This will rebuild subfolders such as `go/` from scratch and store the set of code-generated file names in `go/codegen-manifest.json`. If these outputs look correct, they need to be checked into git and will then serve as the expected values for the normal test runs:
go test ./...
That is, the normal test runs will fail if changes to codegen or schema lead to a diff in the generated file set. If the diff is intentional, it can be accepted again via `PULUMI_ACCEPT=true`.
To support running unit tests over the generated code, the tests also support mixing in manually written `$lang-extras` files into the generated tree. For example, given the following input:
testdata/
my-simple-schema/
schema.json
go/
go-extras/
tests/
go_test.go
The system will copy `go-extras/tests/go_test.go` into `go/tests/go_test.go` before performing compilation and unit test checks over the project generated in `go`.
func TestTypeNameCodegen ¶
func TestTypeNameCodegen(t *testing.T, language string, newTypeNameGenerator NewTypeNameGeneratorFunc)
func ValidateFileEquality ¶
ValidateFileEquality compares maps of files for equality.
Types ¶
type CheckProgramOutput ¶
Checks that a generated program is correct
The arguments are to be read: (Testing environment, path to generated code, set of dependencies)
type CodegenCheck ¶
Defines an extra check logic that accepts the directory with the generated code, typically `$TestDir/$test.Directory/$language`.
type GenPkgSignature ¶
GenPkgSignature corresponds to the shape of the codegen GeneratePackage functions.
type GenProgram ¶
Generates a program from a pcl.Program
type NewTypeNameGeneratorFunc ¶
type NewTypeNameGeneratorFunc func(pkg *schema.Package) TypeNameGeneratorFunc
type ProgramCodegenOptions ¶
type ProgramCodegenOptions struct {
Language string
Extension string
OutputFile string
Check CheckProgramOutput
GenProgram GenProgram
TestCases []ProgramTest
}
type ProgramTest ¶
type SDKCodegenOptions ¶
type SDKCodegenOptions struct {
// Name of the programming language.
Language string
// Language-aware code generator; such as `GeneratePackage`.
// from `codegen/dotnet`.
GenPackage GenPkgSignature
// Extra checks for all the tests. They keys of this map are
// of the form "$language/$check" such as "go/compile".
Checks map[string]CodegenCheck
// The tests to run. A testcase `tt` are assumed to be located at
// ../testing/test/testdata/${tt.Directory}
TestCases []*SDKTest
}
SDKCodegenOptions describes the set of codegen tests for a language.
type SDKTest ¶
type SDKTest struct {
Directory string
Description string
// Extra checks for this test. They keys of this map
// are of the form "$language/$check" such as "go/compile".
Checks map[string]CodegenCheck
// Skip checks, identified by "$language/$check".
// "$language/any" is special, skipping generating the
// code as well as all tests.
Skip codegen.StringSet
// Do not compile the generated code for the languages in this set.
// This is a helper form of `Skip`.
SkipCompileCheck codegen.StringSet
// Mutex to ensure only a single test operates on directory at a time
Mutex sync.Mutex
}
func (*SDKTest) ShouldSkipCodegen ¶
ShouldSkipCodegen determines if codegen should be run. ShouldSkipCodegen=true further implies no other tests will be run.
func (*SDKTest) ShouldSkipTest ¶
ShouldSkipTest indicates if a given test for a given language should be run.
type SchemaVersion ¶
type SchemaVersion = string
const ( AwsSchema SchemaVersion = "4.26.0" AzureNativeSchema SchemaVersion = "1.29.0" AzureSchema SchemaVersion = "4.18.0" KubernetesSchema SchemaVersion = "3.7.2" RandomSchema SchemaVersion = "4.2.0" )
Schemas are downloaded in the makefile, and the versions specified here should be in sync with the makefile.