integration

package
v0.14.0 Latest Latest
Warning

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

Go to latest
Published: Jun 15, 2018 License: Apache-2.0 Imports: 35 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateBasicPulumiRepo

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 GetStacks

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

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 update
pulumi preview (expected to be empty)
pulumi update (expected to be empty)
pulumi destroy --yes
pulumi stack rm --yes integrationtesting

(*) Only if PULUMI_ACCESS_TOKEN is set.

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

func ReplaceInFile

func ReplaceInFile(old, new, path string) error

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

func RunCommand

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.

Types

type EditDir

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

	// 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
}

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

type ProgramTestOptions

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 config keys and values to set (e.g. {"aws:config:region": "us-east-2"})
	Config map[string]string
	// Map of secure config keys and values to set on the stack (e.g. {"aws:config:region": "us-east-2"})
	Secrets map[string]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
	// Quick can be set to true to run a "quick" test that skips any non-essential steps (e.g., empty updates).
	Quick bool
	// UpdateCommandlineFlags specifies flags to add to the `pulumi update` command line (e.g. "--color=raw")
	UpdateCommandlineFlags []string

	// 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
	// PPCName is the name of the PPC to use when running a test against the hosted service. If
	// not set, the --ppc flag will not be set on `pulumi stack init`.
	PPCName 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 invocatoions.
	Tracing string

	// 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 update`, 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

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

ProgramTestOptions provides options for ProgramTest

func (*ProgramTestOptions) GetDebugLogLevel

func (opts *ProgramTestOptions) GetDebugLogLevel() int

func (*ProgramTestOptions) GetDebugUpdates

func (opts *ProgramTestOptions) GetDebugUpdates() bool

func (*ProgramTestOptions) GetStackName

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

GetStackName returns a stack name to use for this test.

func (ProgramTestOptions) With

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

type RuntimeValidationStackInfo

type RuntimeValidationStackInfo struct {
	StackName    tokens.QName
	Deployment   *apitype.Deployment
	RootResource apitype.Resource
	Outputs      map[string]interface{}
}

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

type S3Reporter

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

S3Reporter is a TestStatsReporter that publises test data to S3

func NewS3Reporter

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

func (r *S3Reporter) ReportCommand(stats TestCommandStats)

ReportCommand uploads the results of running a command to S3

type TestCommandStats

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 invoked1
	StepName string `json:"stepName"`
	// CommandLine is the command line which was invoked1
	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"`
	// The PPC that the test was run against, or empty for local deployments or for the default PPC
	CloudPPC string `json:"cloudPPC"`
}

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

type TestStatsReporter

type TestStatsReporter interface {
	ReportCommand(stats TestCommandStats)
}

TestStatsReporter reports results and metadata from a test run.

Jump to

Keyboard shortcuts

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