Help us shape the future of Go! Take the 2026 Go Developer Survey

acctest

package
v1.12.6 Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2026 License: MPL-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (

	// NamePrefix marks every identifier these tests create. Randomising a name
	// stops a failed cleanup from blocking the next run, but on its own it turns
	// each leak into an unattributable resource nobody dares delete. The shared
	// prefix is what makes leaks identifiable afterwards -- by the sweeper, by a
	// dashboard filter, or by a human deciding what is safe to remove.
	NamePrefix = "tfacc"
)

Variables

View Source
var SweepUnsupported = []string{
	"policies (sg-sdk-go ListAllPolicies discards the response body)",
	"roles (sg-sdk-go ListAllRoles discards the response body)",
	"runner groups (sg-sdk-go exposes no list method)",
}

SweepUnsupported names the resource types a sweep cannot reach, so the caller can say so rather than implying the organisation is clean.

Functions

func IsTestResourceName added in v1.12.2

func IsTestResourceName(name string) bool

IsTestResourceName reports whether a name looks like one this suite created. Sweepers use it to decide what is safe to delete, so it is deliberately strict: anything not carrying the prefix is left alone.

func ProviderFactories

func ProviderFactories(customHeader http.Header) map[string]func() (tfprotov6.ProviderServer, error)

func ResourceName added in v1.12.2

func ResourceName(slug string) string

ResourceName returns a unique identifier for one acceptance-test resource, shaped as "tfacc-<slug>-<random>".

Static names made the suite order-dependent: a run that failed before its destroy step left the name taken, and every later run failed at create with 409 "already exists" until somebody deleted it by hand. A fresh name per run removes that coupling.

The slug is kept so a leaked resource still says which test made it.

func ResourceNameRaw added in v1.12.2

func ResourceNameRaw(name string) string

ResourceNameRaw makes a name unique without cleaning it up, for the tests whose subject is an awkward name: one carrying spaces, capitals, or punctuation the platform has to cope with. Sanitising those would leave the test passing while removing the thing it checks.

The prefix and random part lead so the result is still recognisable to IsTestResourceName and to a sweeper.

func SGClient added in v1.3.2

func SGClient() *sgclient.Client

func SkipUnlessAcceptance added in v1.12.4

func SkipUnlessAcceptance(t *testing.T)

SkipUnlessAcceptance skips the calling test unless TF_ACC is set.

resource.Test performs this check itself, but only once it is reached. The acceptance tests in this repository create their API fixtures before that point, so without this guard a run without credentials fails on a 401 rather than skipping. That in turn makes `make test` unusable as a credential-free pull request gate.

Call it as the first statement of every TestAcc function.

func SweepDryRun added in v1.12.2

func SweepDryRun() bool

SweepDryRun reports whether the sweep should only describe what it would do.

func SweepEnabled added in v1.12.2

func SweepEnabled() bool

SweepEnabled reports whether the caller asked for a cleanup pass rather than a normal test run. Kept separate from the sweeper implementations so a package can guard destructive helpers behind it.

func TFStandardErrorPattern added in v1.12.2

func TFStandardErrorPattern(msg string) *regexp.Regexp

TFStandardErrorPattern builds a regexp for resource.TestStep.ExpectError from a literal error message. Terraform's CLI hard-wraps diagnostic text at a fixed column width, so a long message can come back with newlines inserted between words (e.g. "TERRAFORM or\nOPENTOFU" instead of "TERRAFORM or OPENTOFU") — a pattern built with literal spaces silently fails to match whenever a wrap happens to land inside it. This quotes every word and joins them with \s+, so the match tolerates a line break (or any other run of whitespace) wherever the CLI happens to wrap.

func TestAccPreCheck

func TestAccPreCheck(t *testing.T)

func VersionChecks added in v1.12.4

func VersionChecks() []tfversion.TerraformVersionCheck

VersionChecks returns the Terraform CLI version checks every acceptance test case must declare, pinned to the provider's support floor (constants.MinTerraformVersion).

This deliberately uses RequireAbove rather than SkipBelow. SkipBelow *passes* a test when the CLI is older than the floor, so a CI job that resolves the wrong Terraform version would skip all of the tests and report green — a false guarantee. RequireAbove fails loudly instead, which is what we want for the one version we promise to support.

Types

type SweepReport added in v1.12.2

type SweepReport struct {
	DryRun  bool
	Swept   []string
	Skipped int
	Errors  []error
}

SweepReport accumulates what a sweep found.

func Sweep added in v1.12.2

func Sweep(ctx context.Context, client *sgclient.Client, org string) *SweepReport

Sweep removes every test-created resource it can reach in org. It continues past individual failures: one resource that refuses to delete should not hide the rest.

func (*SweepReport) String added in v1.12.2

func (r *SweepReport) String() string

Jump to

Keyboard shortcuts

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