pulumi: github.com/pulumi/pulumi/pkg/testing/integration Index | Files

package integration

import "github.com/pulumi/pulumi/pkg/testing/integration"

Index

Package Files

command.go program.go pulumi.go s3reporter.go util.go

Constants

const DotNetRuntime = "dotnet"
const GoRuntime = "go"
const NodeJSRuntime = "nodejs"
const PythonRuntime = "python"

func CreateBasicPulumiRepo Uses

func CreateBasicPulumiRepo(e *testing.Environment)

CreateBasicPulumiRepo will initialize the environment with a basic Pulumi repository and project file definition. Returns the repo owner and name used.

func DecodeMapString Uses

func DecodeMapString(val string) (map[string]string, error)

DecodeMapString takes a string of the form key1=value1:key2=value2 and returns a go map.

func GetLogs Uses

func GetLogs(
    t *testing.T,
    provider, region string,
    stackInfo RuntimeValidationStackInfo,
    query operations.LogQuery) *[]operations.LogEntry

GetLogs retrieves the logs for a given stack in a particular region making the query provided.

[provider] should be one of "aws" or "azure"

func GetStacks Uses

func GetStacks(e *testing.Environment) ([]string, *string)

GetStacks returns the list of stacks and current stack by scraping `pulumi stack ls`. Assumes .pulumi is in the current working directory. Fails the test on IO errors.

func ProgramTest Uses

func ProgramTest(t *testing.T, opts *ProgramTestOptions)

ProgramTest runs a lifecycle of Pulumi commands in a program working directory, using the `pulumi` and `yarn` binaries available on PATH. It essentially executes the following workflow:

yarn install
yarn link <each opts.Depencies>
(+) yarn run build
pulumi init
(*) pulumi login
pulumi stack init integrationtesting
pulumi config set <each opts.Config>
pulumi config set --secret <each opts.Secrets>
pulumi preview
pulumi up
pulumi stack export --file stack.json
pulumi stack import --file stack.json
pulumi preview (expected to be empty)
pulumi up (expected to be empty)
pulumi destroy --yes
pulumi stack rm --yes integrationtesting

(*) Only if PULUMI_ACCESS_TOKEN is set.
(+) Only if `opts.RunBuild` is true.

All commands must return success return codes for the test to succeed, unless ExpectFailure is true.

func ReplaceInFile Uses

func ReplaceInFile(old, new, path string) error

ReplaceInFile does a find and replace for a given string within a file.

func RunCommand Uses

func RunCommand(t *testing.T, name string, args []string, wd string, opts *ProgramTestOptions) error

RunCommand executes the specified command and additional arguments, wrapping any output in the specialized test output streams that list the location the test is running in.

type ConfigValue Uses

type ConfigValue struct {
    // The config key to pass to `pulumi config`.
    Key string
    // The config value to pass to `pulumi config`.
    Value string
    // Secret indicates that the `--secret` flag should be specified when calling `pulumi config`.
    Secret bool
    // Path indicates that the `--path` flag should be specified when calling `pulumi config`.
    Path bool
}

ConfigValue is used to provide config values to a test program.

type EditDir Uses

type EditDir struct {
    Dir                    string
    ExtraRuntimeValidation func(t *testing.T, stack RuntimeValidationStackInfo)

    // Additive is true if Dir should be copied *on top* of the test directory.
    // Otherwise Dir *replaces* the test directory, except we keep .pulumi/ and Pulumi.yaml and Pulumi.<stack>.yaml.
    Additive bool

    // ExpectFailure is true if we expect this test to fail.  This is very coarse grained, and will essentially
    // tolerate *any* failure in the program (IDEA: in the future, offer a way to narrow this down more).
    ExpectFailure bool

    // ExpectNoChanges is true if the edit is expected to not propose any changes.
    ExpectNoChanges bool

    // Stdout is the writer to use for all stdout messages.
    Stdout io.Writer
    // Stderr is the writer to use for all stderr messages.
    Stderr io.Writer
    // Verbose may be set to true to print messages as they occur, rather than buffering and showing upon failure.
    Verbose bool

    // Run program directory in query mode.
    QueryMode bool
}

EditDir is an optional edit to apply to the example, as subsequent deployments.

type ProgramTestOptions Uses

type ProgramTestOptions struct {
    // Dir is the program directory to test.
    Dir string
    // Array of NPM packages which must be `yarn linked` (e.g. {"pulumi", "@pulumi/aws"})
    Dependencies []string
    // Map of package names to versions. The test will use the specified versions of these packages instead of what
    // is declared in `package.json`.
    Overrides map[string]string
    // Map of config keys and values to set (e.g. {"aws:region": "us-east-2"}).
    Config map[string]string
    // Map of secure config keys and values to set (e.g. {"aws:region": "us-east-2"}).
    Secrets map[string]string
    // List of config keys and values to set in order, including Secret and Path options.
    OrderedConfig []ConfigValue
    // SecretsProvider is the optional custom secrets provider to use instead of the default.
    SecretsProvider string
    // EditDirs is an optional list of edits to apply to the example, as subsequent deployments.
    EditDirs []EditDir
    // ExtraRuntimeValidation is an optional callback for additional validation, called before applying edits.
    ExtraRuntimeValidation func(t *testing.T, stack RuntimeValidationStackInfo)
    // RelativeWorkDir is an optional path relative to `Dir` which should be used as working directory during tests.
    RelativeWorkDir string
    // AllowEmptyPreviewChanges is true if we expect that this test's no-op preview may propose changes (e.g.
    // because the test is sensitive to the exact contents of its working directory and those contents change
    // incidentally between the initial update and the empty update).
    AllowEmptyPreviewChanges bool
    // AllowEmptyUpdateChanges is true if we expect that this test's no-op update may perform changes (e.g.
    // because the test is sensitive to the exact contents of its working directory and those contents change
    // incidentally between the initial update and the empty update).
    AllowEmptyUpdateChanges bool
    // ExpectFailure is true if we expect this test to fail.  This is very coarse grained, and will essentially
    // tolerate *any* failure in the program (IDEA: in the future, offer a way to narrow this down more).
    ExpectFailure bool
    // ExpectRefreshChanges may be set to true if a test is expected to have changes yielded by an immediate refresh.
    // This could occur, for example, is a resource's state is constantly changing outside of Pulumi (e.g., timestamps).
    ExpectRefreshChanges bool
    // SkipRefresh indicates that the refresh step should be skipped entirely.
    SkipRefresh bool
    // SkipStackRemoval indicates that the stack should not be removed. (And so the test's results could be inspected
    // in the Pulumi Service after the test has completed.)
    SkipStackRemoval bool
    // Quick can be set to true to run a "quick" test that skips any non-essential steps (e.g., empty updates).
    Quick bool
    // PreviewCommandlineFlags specifies flags to add to the `pulumi preview` command line (e.g. "--color=raw")
    PreviewCommandlineFlags []string
    // UpdateCommandlineFlags specifies flags to add to the `pulumi up` command line (e.g. "--color=raw")
    UpdateCommandlineFlags []string
    // QueryCommandlineFlags specifies flags to add to the `pulumi query` command line (e.g. "--color=raw")
    QueryCommandlineFlags []string
    // RunBuild indicates that the build step should be run (e.g. run `yarn build` for `nodejs` programs)
    RunBuild bool
    // RunUpdateTest will ensure that updates to the package version can test for spurious diffs
    RunUpdateTest bool

    // CloudURL is an optional URL to override the default Pulumi Service API (https://api.pulumi-staging.io). The
    // PULUMI_ACCESS_TOKEN environment variable must also be set to a valid access token for the target cloud.
    CloudURL string

    // StackName allows the stack name to be explicitly provided instead of computed from the
    // environment during tests.
    StackName string

    // Tracing specifies the Zipkin endpoint if any to use for tracing Pulumi invocations.
    Tracing string
    // NoParallel will opt the test out of being ran in parallel.
    NoParallel bool

    // PrePulumiCommand specifies a callback that will be executed before each `pulumi` invocation. This callback may
    // optionally return another callback to be invoked after the `pulumi` invocation completes.
    PrePulumiCommand func(verb string) (func(err error) error, error)

    // ReportStats optionally specifies how to report results from the test for external collection.
    ReportStats TestStatsReporter

    // Stdout is the writer to use for all stdout messages.
    Stdout io.Writer
    // Stderr is the writer to use for all stderr messages.
    Stderr io.Writer
    // Verbose may be set to true to print messages as they occur, rather than buffering and showing upon failure.
    Verbose bool

    // DebugLogging may be set to anything >0 to enable excessively verbose debug logging from `pulumi`.  This is
    // equivalent to `--logtostderr -v=N`, where N is the value of DebugLogLevel.  This may also be enabled by setting
    // the environment variable PULUMI_TEST_DEBUG_LOG_LEVEL.
    DebugLogLevel int
    // DebugUpdates may be set to true to enable debug logging from `pulumi preview`, `pulumi up`, and
    // `pulumi destroy`.  This may also be enabled by setting the environment variable PULUMI_TEST_DEBUG_UPDATES.
    DebugUpdates bool

    // Bin is a location of a `pulumi` executable to be run.  Taken from the $PATH if missing.
    Bin string
    // YarnBin is a location of a `yarn` executable to be run.  Taken from the $PATH if missing.
    YarnBin string
    // GoBin is a location of a `go` executable to be run.  Taken from the $PATH if missing.
    GoBin string
    // PipenvBin is a location of a `pipenv` executable to run.  Taken from the $PATH if missing.
    PipenvBin string
    // DotNetBin is a location of a `dotnet` executable to be run.  Taken from the $PATH if missing.
    DotNetBin string

    // Additional environment variables to pass for each command we run.
    Env []string
}

ProgramTestOptions provides options for ProgramTest

func (*ProgramTestOptions) GetDebugLogLevel Uses

func (opts *ProgramTestOptions) GetDebugLogLevel() int

func (*ProgramTestOptions) GetDebugUpdates Uses

func (opts *ProgramTestOptions) GetDebugUpdates() bool

func (*ProgramTestOptions) GetStackName Uses

func (opts *ProgramTestOptions) GetStackName() tokens.QName

GetStackName returns a stack name to use for this test.

func (*ProgramTestOptions) GetStackNameWithOwner Uses

func (opts *ProgramTestOptions) GetStackNameWithOwner() tokens.QName

GetStackNameWithOwner gets the name of the stack prepended with an owner, if PULUMI_TEST_OWNER is set. We use this in CI to create test stacks in an organization that all developers have access to, for debugging.

func (ProgramTestOptions) With Uses

func (opts ProgramTestOptions) With(overrides ProgramTestOptions) ProgramTestOptions

With combines a source set of options with a set of overrides.

type RuntimeValidationStackInfo Uses

type RuntimeValidationStackInfo struct {
    StackName    tokens.QName
    Deployment   *apitype.DeploymentV3
    RootResource apitype.ResourceV3
    Outputs      map[string]interface{}
    Events       []apitype.EngineEvent
}

RuntimeValidationStackInfo contains details related to the stack that runtime validation logic may want to use.

type S3Reporter Uses

type S3Reporter struct {
    // contains filtered or unexported fields
}

S3Reporter is a TestStatsReporter that publises test data to S3

func NewS3Reporter Uses

func NewS3Reporter(region string, bucket string, keyPrefix string) *S3Reporter

NewS3Reporter creates a new S3Reporter that puts test results in the given bucket using the keyPrefix.

func (*S3Reporter) ReportCommand Uses

func (r *S3Reporter) ReportCommand(stats TestCommandStats)

ReportCommand uploads the results of running a command to S3

type TestCommandStats Uses

type TestCommandStats struct {
    // StartTime is the time at which the command was started
    StartTime string `json:"startTime"`
    // EndTime is the time at which the command exited
    EndTime string `json:"endTime"`
    // ElapsedSeconds is the time at which the command exited
    ElapsedSeconds float64 `json:"elapsedSeconds"`
    // StackName is the name of the stack
    StackName string `json:"stackName"`
    // TestId is the unique ID of the test run
    TestID string `json:"testId"`
    // StepName is the command line which was invoked
    StepName string `json:"stepName"`
    // CommandLine is the command line which was invoked
    CommandLine string `json:"commandLine"`
    // TestName is the name of the directory in which the test was executed
    TestName string `json:"testName"`
    // IsError is true if the command failed
    IsError bool `json:"isError"`
    // The Cloud that the test was run against, or empty for local deployments
    CloudURL string `json:"cloudURL"`
}

TestCommandStats is a collection of data related to running a single command during a test.

type TestStatsReporter Uses

type TestStatsReporter interface {
    ReportCommand(stats TestCommandStats)
}

TestStatsReporter reports results and metadata from a test run.

Package integration imports 40 packages (graph) and is imported by 1 packages. Updated 2019-11-14. Refresh now. Tools for package owners.