Documentation ¶
Index ¶
- Constants
- func BeEmptyFile() types.GomegaMatcher
- func BeFileWithContents(contentMatcher types.GomegaMatcher) types.GomegaMatcher
- func CanReuseLastBuild(binaryName string, hashVar *string, args interface{}) bool
- func HashBuildArgs(args interface{}) (string, error)
- func LDFlags(overwrites ...Overwrite) []string
- func ObjectKeyFromObject(obj metav1.Object) client.ObjectKey
- func RemoveCleanupAction(p CleanupActionHandle)
- func RunCleanupActions()
- type CleanupActionHandle
- type FakeTerraform
- type Overwrite
- type TestObjects
Constants ¶
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
const (
// FakeTerraformBinary is the name of the fake terraform binary
FakeTerraformBinary = "fake-terraform"
)
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 ¶
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 ¶
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 ObjectKeyFromObject ¶
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 ¶
OverwriteExitCode returns an overwrite that configures the binary to always exit with the given code.
func OverwriteExitCodeForCommands ¶
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 ¶
OverwriteSleepDuration returns an overwrite for the exit code var
func OverwriteTerraformBinary ¶
OverwriteTerraformBinary returns an overwrite for the terraform binary name
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.