test_structure

package
v0.17.3 Latest Latest
Warning

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

Go to latest
Published: Jun 20, 2019 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Overview

Package test_structure allows to set up tests and their environment.

Index

Constants

View Source
const SKIP_STAGE_ENV_VAR_PREFIX = "SKIP_"

SKIP_STAGE_ENV_VAR_PREFIX is the prefix used for skipping stage environment variables.

Variables

This section is empty.

Functions

func CleanupTestData

func CleanupTestData(t *testing.T, path string)

CleanupTestData cleans up the test data at the given path.

func CopyTerraformFolderToTemp

func CopyTerraformFolderToTemp(t *testing.T, rootFolder string, terraformModuleFolder string) string

CopyTerraformFolderToTemp copies the given root folder to a randomly-named temp folder and return the path to the given terraform modules folder within the new temp root folder. This is useful when running multiple tests in parallel against the same set of Terraform files to ensure the tests don't overwrite each other's .terraform working directory and terraform.tfstate files. To ensure relative paths work, we copy over the entire root folder to a temp folder, and then return the path within that temp folder to the given terraform module dir, which is where the actual test will be running. For example, suppose you had the target terraform folder you want to test in "/examples/terraform-aws-example" relative to the repo root. If your tests reside in the "/test" relative to the root, then you will use this as follows:

// Root folder where terraform files should be (relative to the test folder)
rootFolder := ".."

// Relative path to terraform module being tested from the root folder
terraformFolderRelativeToRoot := "examples/terraform-aws-example"

// Copy the terraform folder to a temp folder
tempTestFolder := test_structure.CopyTerraformFolderToTemp(t, rootFolder, terraformFolderRelativeToRoot)

// Make sure to use the temp test folder in the terraform options
terraformOptions := &terraform.Options{
		TerraformDir: tempTestFolder,
}

Note that if any of the SKIP_<stage> environment variables is set, we assume this is a test in the local dev where there are no other concurrent tests running and we want to be able to cache test data between test stages, so in that case, we do NOT copy anything to a temp folder, and return the path to the original terraform module folder instead.

func FormatTestDataPath

func FormatTestDataPath(testFolder string, filename string) string

FormatTestDataPath formats a path to save test data.

func IsTestDataPresent

func IsTestDataPresent(t *testing.T, path string) bool

IsTestDataPresent returns true if a file exists at $path and the test data there is non-empty.

func LoadAmiId deprecated

func LoadAmiId(t *testing.T, testFolder string) string

LoadAmiId loads and unserializes an AMI ID from the given folder. This allows you to reuse an AMI that was created during an earlier setup step in later validation and teardown steps.

Deprecated: Use LoadArtifactID instead.

func LoadArtifactID added in v0.10.0

func LoadArtifactID(t *testing.T, testFolder string) string

LoadArtifactID loads and unserializes an Artifact ID from the given folder. This allows you to reuse an Artifact that was created during an earlier setup step in later validation and teardown steps.

func LoadEc2KeyPair

func LoadEc2KeyPair(t *testing.T, testFolder string) *aws.Ec2Keypair

LoadEc2KeyPair loads and unserializes an Ec2KeyPair from the given folder. This allows you to reuse an Ec2KeyPair that was created during an earlier setup step in later validation and teardown steps.

func LoadInt

func LoadInt(t *testing.T, testFolder string, name string) int

LoadInt loads a uniquely named int value from the given folder. This allows you to reuse one or more int values that were created during an earlier setup step in later steps.

func LoadKubectlOptions added in v0.13.29

func LoadKubectlOptions(t *testing.T, testFolder string) *k8s.KubectlOptions

LoadKubectlOptions loads and unserializes a KubectlOptions from the given folder. This allows you to reuse a KubectlOptions that was created during an earlier setup step in later validation and teardown steps.

func LoadPackerOptions

func LoadPackerOptions(t *testing.T, testFolder string) *packer.Options

LoadPackerOptions loads and unserializes PackerOptions from the given folder. This allows you to reuse a PackerOptions that was created during an earlier setup step in later validation and teardown steps.

func LoadString

func LoadString(t *testing.T, testFolder string, name string) string

LoadString loads and unserializes a uniquely named string value from the given folder. This allows you to reuse one or more string values that were created during an earlier setup step in later steps.

func LoadTerraformOptions

func LoadTerraformOptions(t *testing.T, testFolder string) *terraform.Options

LoadTerraformOptions loads and unserializes TerraformOptions from the given folder. This allows you to reuse a TerraformOptions that was created during an earlier setup step in later validation and teardown steps.

func LoadTestData

func LoadTestData(t *testing.T, path string, value interface{})

LoadTestData loads and unserializes a value stored at the given path. The value should be a pointer to a struct into which the value will be deserialized. This allows you to reuse some sort of test data (e.g., TerraformOptions) from earlier setup steps in later validation and teardown steps.

func RunTestStage

func RunTestStage(t *testing.T, stageName string, stage func())

RunTestStage executes the given test stage (e.g., setup, teardown, validation) if an environment variable of the name `SKIP_<stageName>` (e.g., SKIP_teardown) is not set.

func SaveAmiId deprecated

func SaveAmiId(t *testing.T, testFolder string, amiId string)

SaveAmiId serializes and saves an AMI ID into the given folder. This allows you to build an AMI during setup and to reuse that AMI later during validation and teardown.

Deprecated: Use SaveArtifactID instead.

func SaveArtifactID added in v0.10.0

func SaveArtifactID(t *testing.T, testFolder string, artifactID string)

SaveArtifactID serializes and saves an Artifact ID into the given folder. This allows you to build an Artifact during setup and to reuse that Artifact later during validation and teardown.

func SaveEc2KeyPair

func SaveEc2KeyPair(t *testing.T, testFolder string, keyPair *aws.Ec2Keypair)

SaveEc2KeyPair serializes and saves an Ec2KeyPair into the given folder. This allows you to create an Ec2KeyPair during setup and to reuse that Ec2KeyPair later during validation and teardown.

func SaveInt

func SaveInt(t *testing.T, testFolder string, name string, val int)

SaveInt saves a uniquely named int value into the given folder. This allows you to create one or more int values during one stage -- each with a unique name -- and to reuse those values during later stages.

func SaveKubectlOptions added in v0.13.29

func SaveKubectlOptions(t *testing.T, testFolder string, kubectlOptions *k8s.KubectlOptions)

SaveKubectlOptions serializes and saves KubectlOptions into the given folder. This allows you to create a KubectlOptions during setup and reuse that KubectlOptions later during validation and teardown.

func SavePackerOptions

func SavePackerOptions(t *testing.T, testFolder string, packerOptions *packer.Options)

SavePackerOptions serializes and saves PackerOptions into the given folder. This allows you to create PackerOptions during setup and to reuse that PackerOptions later during validation and teardown.

func SaveString

func SaveString(t *testing.T, testFolder string, name string, val string)

SaveString serializes and saves a uniquely named string value into the given folder. This allows you to create one or more string values during one stage -- each with a unique name -- and to reuse those values during later stages.

func SaveTerraformOptions

func SaveTerraformOptions(t *testing.T, testFolder string, terraformOptions *terraform.Options)

SaveTerraformOptions serializes and saves TerraformOptions into the given folder. This allows you to create TerraformOptions during setup and to reuse that TerraformOptions later during validation and teardown.

func SaveTestData

func SaveTestData(t *testing.T, path string, value interface{})

SaveTestData serializes and saves a value used at test time to the given path. This allows you to create some sort of test data (e.g., TerraformOptions) during setup and to reuse this data later during validation and teardown.

func SkipStageEnvVarSet

func SkipStageEnvVarSet() bool

SkipStageEnvVarSet returns true if an environment variable is set instructing Terratest to skip a test stage. This can be an easy way to tell if the tests are running in a local dev environment vs a CI server.

Types

This section is empty.

Jump to

Keyboard shortcuts

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