utils

package
v1.5.1-0...-f4f0154 Latest Latest
Warning

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

Go to latest
Published: Apr 16, 2024 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// ConfigMainKey is the key for the main.tf file
	ConfigMainKey = "main.tf"
	// ConfigVarsKey is the key for the variables.tf file
	ConfigVarsKey = "variables.tf"
	// VarsKey is the key for the terraform.tfvars file
	VarsKey = "terraform.tfvars"
	// StateKey is the key for the terraform.tfstate file
	StateKey = "terraform.tfstate"
)

these consts are replicated from the production to not reuse them in tests

View Source
const (
	// FakeTerraformBinary is the name of the fake terraform binary
	FakeTerraformBinary = "fake-terraform"
)
View Source
const (
	// TerraformerPackage is the terraformer package path
	TerraformerPackage = "github.com/gardener/terraformer"
)

Variables

This section is empty.

Functions

func BeEmptyFile

func BeEmptyFile() types.GomegaMatcher

BeEmptyFile succeeds if actual is an absolute path to a file, that exists and is empty.

func BeFileWithContents

func BeFileWithContents(contentMatcher types.GomegaMatcher) types.GomegaMatcher

BeFileWithContents succeeds if actual is an absolute path to a file, that exists and its contents matches the given content matcher.

func CanReuseLastBuild

func CanReuseLastBuild(binaryName string, hashVar *string, args interface{}) bool

CanReuseLastBuild calculates a hash for the given build args and compares it the the value, hashVar points to. If they are equal, it returns true, indicating, that the last build can be reused for this test run. Otherwise, it returns false and sets hashVar to the calculated hash.

func HashBuildArgs

func HashBuildArgs(args interface{}) (string, error)

HashBuildArgs returns a hash for an arbitrary set of build args. This allows us to detect, if a test binary really needs to be rebuild or if we can reuse the same binary from the last build. This way we can significantly shorten the runtime of the binary e2e tests, which build terraformer for each test case.

func LDFlags

func LDFlags(overwrites ...Overwrite) []string

LDFlags returns ldflags to pass to `go build` or `gexec.Build` in tests

func ObjectKeyFromObject

func ObjectKeyFromObject(obj metav1.Object) client.ObjectKey

ObjectKeyFromObject returns an ObjectKey for the given object.

func RemoveCleanupAction

func RemoveCleanupAction(p CleanupActionHandle)

RemoveCleanupAction removes a function that was installed by AddCleanupAction.

func RunCleanupActions

func RunCleanupActions()

RunCleanupActions runs all functions installed by AddCleanupAction. It does not remove them (see RemoveCleanupAction) but it does run unlocked, so they may remove themselves.

Types

type CleanupActionHandle

type CleanupActionHandle *int

CleanupActionHandle is an integer pointer type for handling cleanup action

func AddCleanupAction

func AddCleanupAction(fn func()) CleanupActionHandle

AddCleanupAction installs a function that will be called in the event of the whole test being terminated. This allows arbitrary pieces of the overall test to hook into SynchronizedAfterSuite(). The hooks are called in last-in-first-out order.

type FakeTerraform

type FakeTerraform struct {
	// Path is the path to the fake terraform binary
	Path string
}

FakeTerraform models the terraform fake binary

func NewFakeTerraform

func NewFakeTerraform(overwrites ...Overwrite) FakeTerraform

NewFakeTerraform builds a new terraform fake binary, which can be used to mock terraform executions in tests

func (FakeTerraform) TerraformerEnv

func (f FakeTerraform) TerraformerEnv() []string

TerraformerEnv returns the environment variables to use for executing terraformer, so that it will be able to find the fake terraform binary.

type Overwrite

type Overwrite struct {
	VarPath, Value string
}

Overwrite is a variable overwrite which can be passed to -ldflags

func OverwriteExitCode

func OverwriteExitCode(code string) Overwrite

OverwriteExitCode returns an overwrite that configures the binary to always exit with the given code.

func OverwriteExitCodeForCommands

func OverwriteExitCodeForCommands(commandAndCodes ...string) Overwrite

OverwriteExitCodeForCommands returns an overwrite that configures the binary to exit with the given code if it is invoked with the given command. Example usage:

testutils.OverwriteExitCodeForCommands(
	"init", "0",
	"apply", "42",
	"destroy", "43",
),

func OverwriteSleepDuration

func OverwriteSleepDuration(code string) Overwrite

OverwriteSleepDuration returns an overwrite for the exit code var

func OverwriteTerraformBinary

func OverwriteTerraformBinary(path string) Overwrite

OverwriteTerraformBinary returns an overwrite for the terraform binary name

func (Overwrite) String

func (o Overwrite) String() string

type TestObjects

type TestObjects struct {
	Namespace              string
	ConfigurationConfigMap *corev1.ConfigMap
	StateConfigMap         *corev1.ConfigMap
	VariablesSecret        *corev1.Secret
	// contains filtered or unexported fields
}

TestObjects models a set of API objects used in tests

func PrepareTestObjects

func PrepareTestObjects(ctx context.Context, c client.Client, namespacePrefix, terraformVersion string) *TestObjects

PrepareTestObjects creates a default set of needed API objects for tests

func (*TestObjects) CleanupTestObjects

func (o *TestObjects) CleanupTestObjects(ctx context.Context)

CleanupTestObjects take care to remove the finalizers of the secret and configmaps

func (*TestObjects) Refresh

func (o *TestObjects) Refresh()

Refresh retrieves a fresh copy of the objects from the API server, so that tests can make assertions on them.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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