test

package
v3.18.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 17, 2021 License: Apache-2.0 Imports: 25 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckAllFilesGenerated

func CheckAllFilesGenerated(t *testing.T, actual, expected map[string][]byte)

CheckAllFilesGenerated ensures that the set of expected and actual files generated are exactly equivalent.

func CopyExtraFiles added in v3.13.0

func CopyExtraFiles(t *testing.T, dir, lang string)

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

func LoadBaseline(dir, lang string) (map[string][]byte, error)

`LoadBaseline` loads the contents of the given baseline directory, by inspecting its `codegen-manifest.json`.

func LoadFiles

func LoadFiles(dir, lang string, files []string) (map[string][]byte, error)

LoadFiles loads the provided list of files from a directory.

func NoSDKCodegenChecks added in v3.14.0

func NoSDKCodegenChecks() bool

func PathExists added in v3.13.0

func PathExists(path string) (bool, error)

func RewriteFilesWhenPulumiAccept added in v3.2.0

func RewriteFilesWhenPulumiAccept(t *testing.T, dir, lang string, actual map[string][]byte) bool

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 RunCommand(t *testing.T, name string, cwd string, exec string, args ...string)

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

func ValidateFileEquality(t *testing.T, actual, expected map[string][]byte) bool

ValidateFileEquality compares maps of files for equality.

func ValidateFileTransformer added in v3.11.0

func ValidateFileTransformer(
	t *testing.T,
	inputFile string,
	expectedOutputFile string,
	transformer func(reader io.Reader, writer io.Writer) error)

Validates a transformer on a single file.

Types

type CheckProgramOutput added in v3.14.0

type CheckProgramOutput = func(*testing.T, string, codegen.StringSet)

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

type CodegenCheck func(t *testing.T, codedir string)

Defines an extra check logic that accepts the directory with the generated code, typically `$TestDir/$test.Directory/$language`.

type GenPkgSignature

type GenPkgSignature func(string, *schema.Package, map[string][]byte) (map[string][]byte, error)

GenPkgSignature corresponds to the shape of the codegen GeneratePackage functions.

type GenProgram added in v3.14.0

type GenProgram = func(program *pcl.Program) (map[string][]byte, hcl.Diagnostics, error)

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"
)

type TypeNameGeneratorFunc added in v3.7.0

type TypeNameGeneratorFunc func(t schema.Type) string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL