Documentation
¶
Index ¶
- 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 SDKCodegenOptions
- type SchemaVersion
- type TypeNameGeneratorFunc
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CheckAllFilesGenerated ¶
CheckAllFilesGenerated ensures that the set of expected and actual files generated are exactly equivalent.
func CopyExtraFiles ¶ added in v3.13.0
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 ¶ added in v3.6.1
`LoadBaseline` loads the contents of the given baseline directory, by inspecting its `codegen-manifest.json`.
func NoSDKCodegenChecks ¶ added in v3.14.0
func NoSDKCodegenChecks() bool
func PathExists ¶ added in v3.13.0
func RewriteFilesWhenPulumiAccept ¶ added in v3.2.0
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 ¶ added in v3.13.1
func RunCommandWithOptions ¶ added in v3.15.0
func RunCommandWithOptions( t *testing.T, opts *integration.ProgramTestOptions, name string, cwd string, exec string, args ...string)
func TestProgramCodegen ¶ added in v3.9.0
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 ¶ added in v3.6.1
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/internal/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 ¶ added in v3.7.0
func TestTypeNameCodegen(t *testing.T, language string, newTypeNameGenerator NewTypeNameGeneratorFunc)
func ValidateFileEquality ¶
ValidateFileEquality compares maps of files for equality.
Types ¶
type CheckProgramOutput ¶ added in v3.14.0
Checks that a generated program is correct
The arguments are to be read: (Testing environment, path to generated code, set of dependencies)
type CodegenCheck ¶ added in v3.13.0
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 ¶ added in v3.14.0
Generates a program from a pcl.Program
type NewTypeNameGeneratorFunc ¶ added in v3.7.0
type NewTypeNameGeneratorFunc func(pkg *schema.Package) TypeNameGeneratorFunc
type ProgramCodegenOptions ¶ added in v3.16.0
type ProgramCodegenOptions struct {
Language string
Extension string
OutputFile string
Check CheckProgramOutput
GenProgram GenProgram
}
type SDKCodegenOptions ¶ added in v3.13.0
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
}
type SchemaVersion ¶ added in v3.14.0
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" )