fuzzing

package
v3.0.0-...-a5432f4 Latest Latest
Warning

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

Go to latest
Published: Jan 13, 2025 License: Apache-2.0 Imports: 25 Imported by: 0

README

(lifecycle-fuzzing)=

Fuzzing

Snapshot integrity errors are very problematic when they occur and can be hard to spot and prevent. To this end, a subset of the lifecycle test suite uses a combination of fuzzing and property-based testing via the Rapid Go library to randomly generate snapshots and programs to see whether or not it is possible to trigger a snapshot integrity error.

While snapshot integrity issues often happen as part of a chain of snapshot operations (e.g. the execution of multiple steps in a deployment), the precursor to any error state will always be a valid snapshot. Thus, rather than having to generate random chains of operations, we can instead simplify the problem to generating valid starting snapshots and then executing a single random operation on them. The strategy we employ is thus as follows:

  • Generate a snapshot (snapshot.go) consisting of a random set of resources (resource.go), including appropriate providers. Resources may randomly depend on each other, and may have random properties, such as whether they are custom resources or components, pending replacement, and so on.

  • Generate a program (program.go) from the previously generated snapshot. The program may choose to register any subset (including none) of the resources in the snapshot, as well as any set of new resources before, in between and after those specified in the snapshot. Resources from the snapshot that are registered may be copied as-is or registered with different properties.

  • Generate a set of provider implementations for the program (provider.go). Provider operations such as , , etc. may be configured to fail randomly, or return one of a set of random results (e.g. an update vs a replace for Diff), on a per-resource basis.

  • Generate an operation (one of preview, up, refresh and destroy) and associated configuration (such as a list of --targets), known in the test suite as a plan to execute (plan.go).

  • Combine the snapshot, program, providers and plan to form a fixture (fixture.go) and execute it. If the operation yields a valid snapshot, the test passes, whether the operation completes successfully or not. If an invalid snapshot is produced, the test fails and the reproducing combination of snapshot, program, providers and plan is returned for debugging.

In the event that a failing test case is found, the reproducing fixture will be pretty printed to the screen and code for a reproducing test case will be written to a file to aid in debugging. See fixture.go and reprogen.go for more details.

:::{note} By default, reproduction test files will be written to a temporary directory. A specific directory can be configured using the CODEINFRA_LIFECYCLE_TEST_FUZZING_REPRO_DIR environment variable. :::

Running a suite of fuzz tests

The TestFuzz test generates and tests a set of fixtures, and can be run with the top-level test_lifecycle_fuzz target:

make test_lifecycle_fuzz

You can change how many checks Rapid performs by setting the LIFECYCLE_TEST_FUZZ_CHECKS Make variable on the command line. For instance, to perform 10,000 checks:

make test_lifecycle_fuzz LIFECYCLE_TEST_FUZZ_CHECKS=10000

If you use go test directly, make sure you set the CODEINFRA_LIFECYCLE_TEST_FUZZ variable to something; the test will be skipped if you do not:

(cd pkg/engine/lifecycletest; CODEINFRA_LIFECYCLE_TEST_FUZZ=1 go test ./... -run '^TestFuzz$')

Starting from a known state

Rather than generating entirely random scenarios, it can be useful to start from a known snapshot, and to fuzz potential provider configurations and operations, etc. from there. The TestFuzzFromStateFile test is provided to this end. It will read state from a JSON file (such as that produced by a codeinfra stack export command) and use this as the starting point for a fuzzing run. Use the CODEINFRA_LIFECYCLE_TEST_FUZZ_FROM_STATE_FILE environment variable to specify the file to read (if this variable is not set, the test will be skipped):

CODEINFRA_LIFECYCLE_TEST_FUZZ_FROM_STATE_FILE=/path/to/state.json \
    make test_lifecycle_fuzz_from_state_file \
    LIFECYCLE_TEST_FUZZ_CHECKS=10000

In this example we have again configured 10,000 Rapid checks using the LIFECYCLE_TEST_FUZZ_CHECKS Make variable as before.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var GeneratedProviderType = rapid.Custom(func(t *rapid.T) tokens.Type {
	pkg := rapid.StringMatching("^pkg-[a-z][A-Za-z0-9]{3}$").Draw(t, "ProviderType.Package")
	return tokens.Type("codeinfra:providers:" + pkg)
})

A rapid.Generator that yields random provider types.

GeneratedProviderType.Draw(t, "ProviderType") = "codeinfra:providers:<pkg>"
View Source
var GeneratedResourceID = rapid.Custom(func(t *rapid.T) resource.ID {
	id := rapid.StringMatching("^id-[a-z][A-Za-z0-9]{11}$").Draw(t, "ResourceID")
	return resource.ID(id)
})

A rapid.Generator that yields random resource IDs.

GeneratedResourceID.Draw(t, "ResourceID") = "id-<random>"
View Source
var GeneratedResourceName = rapid.Custom(func(t *rapid.T) string {
	name := rapid.StringMatching("^res-[a-z][A-Za-z0-9]{3}$").Draw(t, "ResourceName")
	return name
})

A rapid.Generator that yields random resource names.

GeneratedResourceName.Draw(t, "ResourceName") = "res-<random>"

Functions

func AddTag

func AddTag[T ~string](r *ResourceSpec, tag T)

AddTag adds the given tag to the given ResourceSpec. Ideally this would be a generic method on ResourceSpec itself, but Go doesn't support generic methods yet.

func ColorFor

func ColorFor(s string) *color.Color

ColorFor accepts a string and hashes it to produce an RGB color. This is useful for making e.g. different URNs easy to identify by giving them unique colors when pretty-printing them.

func Colored

func Colored[T ~string](t T) string

Colored generates a color from the given string and colors the string with it.

func GenerateReproTest

func GenerateReproTest(
	t lt.TB,
	sso StackSpecOptions,
	snapSpec *SnapshotSpec,
	progSpec *ProgramSpec,
	provSpec *ProviderSpec,
	planSpec *PlanSpec,
) string

GenerateReproTest generates a string containing Go code for a set of lifecycle tests that reproduce the scenario captured by the given *Specs.

func GeneratedFixture

func GeneratedFixture(fo FixtureOptions) func(t *rapid.T)

Given a set of options, returns a Rapid property test function that generates and tests fixtures according to that configuration.

func GeneratedPlanSpec

func GeneratedPlanSpec(ss *SnapshotSpec, pso PlanSpecOptions) *rapid.Generator[*PlanSpec]

Given a SnapshotSpec and a set of options, returns a rapid.Generator that will produce PlanSpecs that can be executed against the specified snapshot.

func GeneratedProgramSpec

func GeneratedProgramSpec(
	ss *SnapshotSpec,
	sso StackSpecOptions,
	pso ProgramSpecOptions,
) *rapid.Generator[*ProgramSpec]

Given a SnapshotSpec and a set of options, returns a rapid.Generator that will produce ProgramSpecs that operate upon the specified snapshot.

func GeneratedProviderResourceSpec

func GeneratedProviderResourceSpec(
	sso StackSpecOptions,
) *rapid.Generator[*ResourceSpec]

Given a set of StackSpecOptions, returns a rapid.Generator that yields random provider ResourceSpecs with no dependencies. Provider resources are always custom and never deleted.

func GeneratedProviderSpec

func GeneratedProviderSpec(progSpec *ProgramSpec, pso ProviderSpecOptions) *rapid.Generator[*ProviderSpec]

Given a ProgramSpec and a set of ProviderSpecOptions, returns a rapid.Generator that will produce random ProviderSpecs that affect the resources defined in the ProgramSpec.

func GeneratedResourceDependencies

func GeneratedResourceDependencies(
	ss *SnapshotSpec,
	r *ResourceSpec,
	include func(*ResourceSpec) bool,
) *rapid.Generator[*ResourceDependenciesSpec]

Given a SnapshotSpec and ResourceSpec, returns a rapid.Generator that yields random (valid) sets of dependencies for the given resource on resources in the given snapshot.

func GeneratedResourceSpec

func GeneratedResourceSpec(
	sso StackSpecOptions,
	rso ResourceSpecOptions,
	provs map[tokens.Package]*ResourceSpec,
) *rapid.Generator[*ResourceSpec]

Given a set of StackSpecOptions, ResourceSpecOptions, and a map of package names to provider resources, returns a rapid.Generator that yields random ResourceSpecs with no dependencies.

func GeneratedResourceType

func GeneratedResourceType(pkg tokens.Package) *rapid.Generator[tokens.Type]

Given a package name, returns a rapid.Generator that yields random resource types within that package.

GeneratedResourceType("pkg-xyz").Draw(t, "ResourceType") = "pkg-xyz:<mod>:<type>"

func GeneratedSnapshotSpec

func GeneratedSnapshotSpec(sso StackSpecOptions, snso SnapshotSpecOptions) *rapid.Generator[*SnapshotSpec]

Given a set of StackSpecOptions and SnapshotSpecOptions, returns a rapid.Generator that yields random SnapshotSpecs.

Types

type FixtureOptions

type FixtureOptions struct {
	StackSpecOptions    StackSpecOptions
	SnapshotSpecOptions SnapshotSpecOptions
	ProgramSpecOptions  ProgramSpecOptions
	ProviderSpecOptions ProviderSpecOptions
	PlanSpecOptions     PlanSpecOptions
}

A set of options for configuring the generation of a fuzzing lifecycle test fixture. A fixture comprises a stack, an initial snapshot, a program to execute against that snapshot, a set of providers to use when executing the program, and a plan to execute and observe the results of.

func (FixtureOptions) With

func (fo FixtureOptions) With(overrides FixtureOptions) FixtureOptions

Returns a copy of the FixtureOptions with the given overrides applied.

type OperationSpec

type OperationSpec string

The type of operations that may be executed as part of a PlanSpec.

const (
	// An update operation.
	PlanOperationUpdate OperationSpec = "plan.update"
	// A refresh operation.
	PlanOperationRefresh OperationSpec = "plan.refresh"
	// A destroy operation.
	PlanOperationDestroy OperationSpec = "plan.destroy"
)

type PlanSpec

type PlanSpec struct {
	// The operation that will be executed (e.g. update, refresh, destroy).
	Operation OperationSpec
	// The set of target URNs that will be passed to the operation, if any.
	TargetURNs []resource.URN
}

A PlanSpec specifies a lifecycle test operation that executes some program against an initial snapshot using a configured set of providers.

func (*PlanSpec) Executors

func (ps *PlanSpec) Executors(t lt.TB, hostF deploytest.PluginHostFactory) (lt.TestUpdateOptions, lt.TestOp)

Returns a set of test options and a test operation that can be used to execute this PlanSpec as part of a lifecycle test.

func (*PlanSpec) Pretty

func (ps *PlanSpec) Pretty(indent string) string

Implements PrettySpec.Pretty. Returns a human-readable string representation of this PlanSpec, suitable for use in debugging output and error messages.

type PlanSpecOptions

type PlanSpecOptions struct {
	// A generator for operations that might be planned.
	Operation *rapid.Generator[OperationSpec]

	// A source set of targets that should be used literally, skipping the target generation process.
	SourceTargets []resource.URN

	// A generator for the maximum number of resources to target in a plan.
	TargetCount *rapid.Generator[int]
}

A set of options for configuring the generation of a PlanSpec.

func (PlanSpecOptions) With

func (pso PlanSpecOptions) With(overrides PlanSpecOptions) PlanSpecOptions

Returns a copy of the given PlanSpecOptions with the given overrides applied.

type PrettySpec

type PrettySpec interface {
	// Returns a pretty human-readable string representation of this spec.
	Pretty(indent string) string
}

PrettySpecs can be pretty-printed as human-readable strings for use in debugging output and error messages.

type ProgramResourceTag

type ProgramResourceTag string

The type of tags that may be added to resources in a ProgramSpec.

const (
	// Tags a resource as having been newly prepended to the program.
	NewlyPrependedProgramResource ProgramResourceTag = "program.newly-prepended"

	// Tags a resource as having been dropped from the program.
	DroppedProgramResource ProgramResourceTag = "program.dropped"

	// Tags a resource as having been newly inserted into the program (that is, between two resources that already exist
	// in the snapshot the program will execute against).
	NewlyInsertedProgramResource ProgramResourceTag = "program.newly-inserted"

	// Tags a resource as having been updated in the program (that is, provided a new set of inputs to those held in the
	// snapshot that the program will execute against).
	UpdatedProgramResource ProgramResourceTag = "program.updated"

	// Tags a resource as having been copied from the snapshot the program will execute against.
	CopiedProgramResource ProgramResourceTag = "program.copied"

	// Tags a resource as having been newly appended to the program.
	NewlyAppendedProgramResource ProgramResourceTag = "program.newly-appended"
)

type ProgramSpec

type ProgramSpec struct {
	// The set of resource registrations made by the program.
	ResourceRegistrations []*ResourceSpec

	// The set of resources present in the snapshot the program will execute against that will *not* be registered (that
	// is, they will be "dropped").
	Drops []*ResourceSpec
}

A ProgramSpec specifies a Codeinfra program whose execution will be mocked in a lifecycle test in order to register resources.

func (*ProgramSpec) AsLanguageRuntimeF

func (ps *ProgramSpec) AsLanguageRuntimeF(t require.TestingT) deploytest.LanguageRuntimeFactory

Returns a new LanguageRuntimeFactory that will register the resources specified in this ProgramSpec when executed.

func (*ProgramSpec) Pretty

func (ps *ProgramSpec) Pretty(indent string) string

Implements PrettySpec.Pretty. Returns a human-readable representation of this ProgramSpec, suitable for use in debugging output and error messages.

type ProgramSpecAction

type ProgramSpecAction string

The set of actions that may be taken on resources in a ProgramSpec.

const (
	// Deletes a resource from the program.
	ProgramSpecDelete ProgramSpecAction = "delete"
	// Inserts a new resource into the program.
	ProgramSpecInsert ProgramSpecAction = "insert"
	// Updates a resource in the program.
	ProgramSpecUpdate ProgramSpecAction = "update"
	// Copies a resource from the snapshot the program will execute against.
	ProgramSpecCopy ProgramSpecAction = "copy"
)

type ProgramSpecOptions

type ProgramSpecOptions struct {
	PrependCount         *rapid.Generator[int]
	PrependResourceOpts  ResourceSpecOptions
	Action               *rapid.Generator[ProgramSpecAction]
	InsertResourceOpts   ResourceSpecOptions
	UpdateProtect        *rapid.Generator[bool]
	UpdateRetainOnDelete *rapid.Generator[bool]
	AddAliases           *rapid.Generator[bool]
	AppendCount          *rapid.Generator[int]
	AppendResourceOpts   ResourceSpecOptions
}

A set of options for configuring the generation of a ProgramSpec.

func (ProgramSpecOptions) With

Returns a copy of the given ProgramSpecOptions with the given overrides applied.

type ProviderCreateSpec

type ProviderCreateSpec map[resource.URN]ProviderCreateSpecAction

A ProviderCreateSpec specifies the behavior of a provider's create function. It maps resource URNs to the action that should be taken if Create is called on that URN. The absence of a URN in the map indicates that the default behavior (a successful create) should be taken.

func (ProviderCreateSpec) AsCreateF

Returns a CreateF-compatible callback that implements this ProviderCreateSpec.

func (ProviderCreateSpec) Pretty

func (pcs ProviderCreateSpec) Pretty(indent string) string

Implements PrettySpec.Pretty. Returns a human-readable string representation of this ProviderCreateSpec, suitable for use in debugging output or error messages.

type ProviderCreateSpecAction

type ProviderCreateSpecAction string

ProviderCreateSpecAction captures the set of actions that can be taken by a Create implementation for a given resource.

const (
	// Fail the Create operation.
	ProviderCreateFailure ProviderCreateSpecAction = "provider.create-failure"
)

type ProviderDeleteSpec

type ProviderDeleteSpec map[resource.URN]ProviderDeleteSpecAction

A ProviderDeleteSpec specifies the behavior of a provider's delete function. It maps resource URNs to the action that should be taken if Delete is called on that URN. The absence of a URN in the map indicates that the default behavior (a successful delete) should be taken.

func (ProviderDeleteSpec) AsDeleteF

Returns a DeleteF-compatible callback that implements this ProviderDeleteSpec.

func (ProviderDeleteSpec) Pretty

func (pds ProviderDeleteSpec) Pretty(indent string) string

Implements PrettySpec.Pretty. Returns a human-readable string representation of this ProviderDeleteSpec, suitable for use in debugging output or error messages.

type ProviderDeleteSpecAction

type ProviderDeleteSpecAction string

ProviderDeleteSpecAction captures the set of actions that can be taken by a Delete implementation for a given resource.

const (
	// Fail the Delete operation.
	ProviderDeleteFailure ProviderDeleteSpecAction = "provider.delete-failure"
)

type ProviderDiffSpec

type ProviderDiffSpec map[resource.URN]ProviderDiffSpecAction

A ProviderDiffSpec specifies the behavior of a provider's diff function. It maps resource URNs to the action that should be taken if Diff is called on that URN. The absence of a URN in the map indicates that the default behavior (a successful diff that reports no changes) should be taken.

func (ProviderDiffSpec) AsDiffF

Returns a DiffF-compatible callback that implements this ProviderDiffSpec.

func (ProviderDiffSpec) Pretty

func (pds ProviderDiffSpec) Pretty(indent string) string

Implements PrettySpec.Pretty. Returns a human-readable string representation of this ProviderDiffSpec, suitable for use in debugging output or error messages.

type ProviderDiffSpecAction

type ProviderDiffSpecAction string

ProviderDiffSpecAction captures the set of actions that can be taken by a Diff implementation for a given resource.

const (
	// Return a diff that indicates that the resource should be deleted before being replaced.
	ProviderDiffDeleteBeforeReplace ProviderDiffSpecAction = "provider.diff-delete-before-replace"
	// Return a diff that indicates that the resource should be replaced by first creating a replacement.
	ProviderDiffDeleteAfterReplace ProviderDiffSpecAction = "provider.diff-delete-after-replace"
	// Return a diff that indicates that the resource should be updated in place.
	ProviderDiffChange ProviderDiffSpecAction = "provider.diff-change"
	// Fail the Diff operation.
	ProviderDiffFailure ProviderDiffSpecAction = "provider.diff-failure"
)

type ProviderReadSpec

type ProviderReadSpec map[resource.URN]ProviderReadSpecAction

A ProviderReadSpec specifies the behavior of a provider's read function. It maps resource URNs to the action that should be taken if Read is called on that URN. The absence of a URN in the map indicates that the default behavior (a successful read that reports that the resource exists) should be taken.

func (ProviderReadSpec) AsReadF

Returns a ReadF-compatible callback that implements this ProviderReadSpec.

func (ProviderReadSpec) Pretty

func (prs ProviderReadSpec) Pretty(indent string) string

Implements PrettySpec.Pretty. Returns a human-readable string representation of this ProviderReadSpec, suitable for use in debugging output or error messages.

type ProviderReadSpecAction

type ProviderReadSpecAction string

ProviderReadSpecAction captures the set of actions that can be taken by a Read implementation for a given resource.

const (
	// Return a result that indicates that the resource has been deleted.
	ProviderReadDeleted ProviderReadSpecAction = "provider.read-deleted"
	// Fail the Read operation.
	ProviderReadFailure ProviderReadSpecAction = "provider.read-failure"
)

type ProviderSpec

type ProviderSpec struct {
	Packages map[tokens.Package]bool
	Create   ProviderCreateSpec
	Delete   ProviderDeleteSpec
	Diff     ProviderDiffSpec
	Read     ProviderReadSpec
	Update   ProviderUpdateSpec
}

A ProviderSpec specifies the behavior of a set of providers that will be mocked in a lifecycle test.

func (*ProviderSpec) AddPackage

func (ps *ProviderSpec) AddPackage(pkg tokens.Package)

Adds the given package to the set of packages that this ProviderSpec will mock.

func (*ProviderSpec) AsProviderLoaders

func (ps *ProviderSpec) AsProviderLoaders() []*deploytest.ProviderLoader

Returns a deploytest.ProviderLoader representation of this ProviderSpec, suitable for use in a lifecycle test.

func (*ProviderSpec) Pretty

func (ps *ProviderSpec) Pretty(indent string) string

Implements PrettySpec.Pretty. Returns a human-readable representation of this ProviderSpec, suitable for use in debugging output and error messages.

type ProviderSpecOptions

A set of options for configuring the generation of a ProviderSpec.

func (ProviderSpecOptions) With

Returns a copy of the given ProviderSpecOptions with the given overrides applied.

type ProviderUpdateSpec

type ProviderUpdateSpec map[resource.URN]ProviderUpdateSpecAction

A ProviderUpdateSpec specifies the behavior of a provider's update function. It maps resource URNs to the action that should be taken if Update is called on that URN. The absence of a URN in the map indicates that the default behavior (a successful update) should be taken.

func (ProviderUpdateSpec) AsUpdateF

Returns an UpdateF-compatible callback that implements this ProviderUpdateSpec.

func (ProviderUpdateSpec) Pretty

func (pus ProviderUpdateSpec) Pretty(indent string) string

Implements PrettySpec.Pretty. Returns a human-readable string representation of this ProviderUpdateSpec, suitable for use in debugging output and error messages.

type ProviderUpdateSpecAction

type ProviderUpdateSpecAction string

ProviderUpdateSpecAction captures the set of actions that can be taken by an Update implementation for a given resource.

const (
	// Fail the Update operation.
	ProviderUpdateFailure ProviderUpdateSpecAction = "provider.update-failure"
)

type ResourceDependenciesSpec

type ResourceDependenciesSpec struct {
	Parent               resource.URN
	Dependencies         []resource.URN
	PropertyDependencies map[resource.PropertyKey][]resource.URN
	DeletedWith          resource.URN
}

A ResourceDependenciesSpec specifies the dependencies of a resource in a snapshot.

func (*ResourceDependenciesSpec) ApplyTo

func (rds *ResourceDependenciesSpec) ApplyTo(r *ResourceSpec)

ApplyTo applies the dependencies specified in this ResourceDependenciesSpec to the given ResourceSpec.

type ResourceSpec

type ResourceSpec struct {
	Project              tokens.PackageName
	Stack                tokens.QName
	Type                 tokens.Type
	Name                 string
	ID                   resource.ID
	Custom               bool
	Delete               bool
	Protect              bool
	PendingReplacement   bool
	RetainOnDelete       bool
	Provider             string
	Parent               resource.URN
	Dependencies         []resource.URN
	PropertyDependencies map[resource.PropertyKey][]resource.URN
	DeletedWith          resource.URN
	Aliases              []resource.URN

	// A set of tags associated with the resource. These have no bearing on any tests but are included to aid in debugging
	// and identifying the causes of snapshot integrity issues.
	Tags map[string]bool
}

A ResourceSpec specifies the subset of a resource's state that is relevant to fuzzing snapshot integrity issues. Generally this encompasses enough to identify a resource (URN, ID, and so on) and any dependencies it may have on others.

func FromResource

func FromResource(r *resource.State) *ResourceSpec

Creates a ResourceSpec from the given resource.State.

func FromResourceV3

func FromResourceV3(r apitype.ResourceV3) *ResourceSpec

Creates a ResourceSpec from the given ResourceV3.

func (*ResourceSpec) AsResource

func (r *ResourceSpec) AsResource() *resource.State

Returns a resource.State representation of this ResourceSpec, suitable for inclusion in e.g. a snapshot.

func (*ResourceSpec) Copy

func (r *ResourceSpec) Copy() *ResourceSpec

Copy returns a deep copy of this ResourceSpec.

func (*ResourceSpec) Pretty

func (r *ResourceSpec) Pretty(indent string) string

Implements PrettySpec.Pretty. Returns a human-readable representation of this ResourceSpec, suitable for use in debugging output and error messages.

<urn> [provider, custom]

Tags:                program.updated, snapshot.provider.initial

Protect:             false
Pending replacement: false
Retain on delete:    false

Dependencies (1):
  <urn>

func (*ResourceSpec) URN

func (r *ResourceSpec) URN() resource.URN

URN returns the URN of this ResourceSpec.

type ResourceSpecOptions

type ResourceSpecOptions struct {
	Custom             *rapid.Generator[bool]
	Protect            *rapid.Generator[bool]
	PendingReplacement *rapid.Generator[bool]
	RetainOnDelete     *rapid.Generator[bool]
}

A set of options for configuring the generation of a ResourceSpec.

func (ResourceSpecOptions) With

Returns a copy of the given ResourceSpecOptions with the given overrides applied.

type SnapshotSpec

type SnapshotSpec struct {
	// A mapping from package names to provider resources. The provider resources will also be included in the Resources
	// slice -- this field serves as a means to quickly look up provider resources by package name.
	Providers map[tokens.Package]*ResourceSpec

	// The set of resources in the snapshot.
	Resources []*ResourceSpec
}

A SnapshotSpec specifies a snapshot containing a set of resources managed by a set of providers.

func FromDeploymentV3

func FromDeploymentV3(d *apitype.DeploymentV3) *SnapshotSpec

Creates a SnapshotSpec from the ResourceV3s in the given DeploymentV3.

func FromSnapshot

func FromSnapshot(s *deploy.Snapshot) *SnapshotSpec

Creates a SnapshotSpec from the given deploy.Snapshot.

func (*SnapshotSpec) AddProvider

func (s *SnapshotSpec) AddProvider(r *ResourceSpec)

Adds the given provider to the snapshot's lookup table and list of resources.

func (*SnapshotSpec) AddResource

func (s *SnapshotSpec) AddResource(r *ResourceSpec)

Adds the given resource to the snapshot.

func (*SnapshotSpec) AsSnapshot

func (s *SnapshotSpec) AsSnapshot() *deploy.Snapshot

Returns a deploy.Snapshot representation of this SnapshotSpec, suitable for use in setting up a lifecycle test.

func (*SnapshotSpec) Pretty

func (s *SnapshotSpec) Pretty(indent string) string

Implements PrettySpec.Pretty. Returns a human-readable string representation of this SnapshotSpec, suitable for use in debugging output and error messages.

type SnapshotSpecAction

type SnapshotSpecAction string

The type of action to take when generating a resource in a snapshot.

const (
	// Generate a new resource.
	SnapshotSpecNew SnapshotSpecAction = "snapshot.new"
	// Generate an old (deleted) version of an existing resource in the snapshot.
	SnapshotSpecOld SnapshotSpecAction = "snapshot.old"
	// Generate a provider resource.
	SnapshotSpecProvider SnapshotSpecAction = "snapshot.provider"
)

type SnapshotSpecOptions

type SnapshotSpecOptions struct {
	// A source DeploymentV3 from which resources should be taken literally,
	// skipping the generation process.
	SourceDeploymentV3 *apitype.DeploymentV3

	// A generator for the maximum number of resources to generate in the snapshot.
	ResourceCount *rapid.Generator[int]

	// A generator for actions that should be taken when generating a snapshot.
	Action *rapid.Generator[SnapshotSpecAction]

	// A set of options for configuring the generation of resources in the snapshot.
	ResourceOpts ResourceSpecOptions
}

A set of options for configuring the generation of a SnapshotSpec.

func (SnapshotSpecOptions) With

Returns a copy of the given SnapshotSpecOptions with the given overrides applied.

type StackSpecOptions

type StackSpecOptions struct {
	Project string
	Stack   string
}

A set of options for configuring stacks used by rapid.Generators in this package.

func (StackSpecOptions) With

Returns a copy of the StackSpecOptions with the given overrides applied.

Jump to

Keyboard shortcuts

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