Documentation
¶
Overview ¶
Package testhelper General helper functions that can be used in tests
Index ¶
- Constants
- func GetBeforeAfterDiff(jsonString string) string
- func GetBestPowerSystemsRegion(apiKey string, prefsFilePath string, defaultRegion string) (string, error)
- func GetBestPowerSystemsRegionO(apiKey string, prefsFilePath string, defaultRegion string, ...) (string, error)
- func GetBestVpcRegion(apiKey string, prefsFilePath string, defaultRegion string) (string, error)
- func GetBestVpcRegionO(apiKey string, prefsFilePath string, defaultRegion string, ...) (string, error)
- func GetRequiredEnvVars(t *testing.T, variableNames []string) map[string]string
- func GetTagsFromTravis() []string
- func GitRootPath(fromPath string) (string, error)
- func RemoveFromStateFile(stateFile string, resourceAddress string) (string, error)
- type EnvironmentVariables
- type Exemptions
- type TestOptions
- func (options *TestOptions) Clone() (*TestOptions, error)
- func (options *TestOptions) RunTest() (string, error)
- func (options *TestOptions) RunTestConsistency() (*terraform.PlanStruct, error)
- func (options *TestOptions) RunTestPlan() (*terraform.PlanStruct, error)
- func (options *TestOptions) RunTestUpgrade() (*terraform.PlanStruct, error)
- type TesthelperTerraformOptions
Constants ¶
const ForceTestRegionEnvName = "FORCE_TEST_REGION"
Variables ¶
This section is empty.
Functions ¶
func GetBeforeAfterDiff ¶ added in v1.2.16
GetBeforeAfterDiff takes a JSON string as input and returns a string with the differences between the "before" and "after" objects in the JSON.
For example, given the JSON string:
{"before": {"a": 1, "b": 2}, "after": {"a": 2, "b": 3}}
the function would return the string:
"Before: {"b": 2}\nAfter: {"a": 2, "b": 3}"
func GetBestPowerSystemsRegion ¶ added in v1.1.3
func GetBestPowerSystemsRegion(apiKey string, prefsFilePath string, defaultRegion string) (string, error)
GetBestPowerSystemsRegion is a method that will determine a region available to the caller account that currently contains the least amount of deployed PowerVS Cloud Connections. The determination can be influenced by specifying a prefsFilePath pointed to a valid YAML file. If an OS ENV is found called FORCE_TEST_REGION then it will be used without querying. This function assumes that all default Options will be used. Returns a string representing an IBM Cloud region name, and error.
func GetBestPowerSystemsRegionO ¶ added in v1.1.3
func GetBestPowerSystemsRegionO(apiKey string, prefsFilePath string, defaultRegion string, options TesthelperTerraformOptions) (string, error)
GetBestPowerSystemsRegionO is a method that will determine a region available to the caller account that currently contains the least amount of deployed PowerVS Cloud Connections. The determination can be influenced by specifying a prefsFilePath pointed to a valid YAML file. If an OS ENV is found called FORCE_TEST_REGION then it will be used without querying. Options data can also be called to supply the service to use that implements the correct interface. Returns a string representing an IBM Cloud region name, and error.
func GetBestVpcRegion ¶
GetBestVpcRegion is a method that will determine a region available to the caller account that currently contains the least amount of deployed VPCs. The determination can be influenced by specifying a prefsFilePath pointed to a valid YAML file. If an OS ENV is found called FORCE_TEST_REGION then it will be used without querying. This function assumes that all default Options will be used. Returns a string representing an IBM Cloud region name, and error.
func GetBestVpcRegionO ¶
func GetBestVpcRegionO(apiKey string, prefsFilePath string, defaultRegion string, options TesthelperTerraformOptions) (string, error)
GetBestVpcRegionO is a method that will determine a region available to the caller account that currently contains the least amount of deployed VPCs. The determination can be influenced by specifying a prefsFilePath pointed to a valid YAML file. If an OS ENV is found called FORCE_TEST_REGION then it will be used without querying. Options data can also be called to supply the service to use that implements the correct interface. Returns a string representing an IBM Cloud region name, and error.
func GetRequiredEnvVars ¶
GetRequiredEnvVars returns a map containing required environment variables and their values Fails the test if any are missing
func GetTagsFromTravis ¶
func GetTagsFromTravis() []string
GetTagsFromTravis Generates a list of tags to add to resources if running in Travis. Returns empty list if not in Travis
func GitRootPath ¶
GitRootPath gets the path to the current git repos root directory
Types ¶
type EnvironmentVariables ¶
EnvironmentVariables Holds a list of environment variables and their values When SetEnvironmentVariables is called it will save any existing environment variables in OldVariables and set NewVariables on the environment When ResetEnvironmentVariables is called it will set the environment variables back to the old values
func (EnvironmentVariables) ResetEnvironmentVariables ¶
func (environment EnvironmentVariables) ResetEnvironmentVariables()
func (EnvironmentVariables) SetEnvironmentVariables ¶
func (environment EnvironmentVariables) SetEnvironmentVariables()
type Exemptions ¶
type Exemptions struct {
List []string
}
Exemptions Struct to hold the list of exemptions
func (Exemptions) IsExemptedResource ¶
func (exemptions Exemptions) IsExemptedResource(resource string) bool
IsExemptedResource Checks if resource string is in the list of exemptions
type TestOptions ¶
type TestOptions struct { BestRegionYAMLPath string // BestRegionYAMLPath Path to the yaml containing regions and weights DefaultRegion string // DefaultRegion default region if automatic detection fails ResourceGroup string // ResourceGroup IBM Cloud resource group to use Region string // Region to use TerraformVars map[string]interface{} // TerraformVars variables to pass to terraform TerraformDir string // TerraformDir Directory Terraform files are in TerraformOptions *terraform.Options `copier:"-"` // TerraformOptions Terraform options to use UseTerraformWorkspace bool // UseTerraformWorkspace Use a Terraform workspace WorkspaceName string // WorkspaceName name of the workspace WorkspacePath string // WorkspacePath path to workspace RequiredEnvironmentVars map[string]string // RequiredEnvironmentVars Tags []string // Tags optional tags to add Prefix string // Prefix to use when creating resources IgnoreAdds Exemptions // IgnoreAdds ignore adds (creates) to these resources in Consistency and Upgrade tests IgnoreDestroys Exemptions // IgnoreDestroys ignore destroys to these resources in Consistency and Upgrade tests IgnoreUpdates Exemptions // IgnoreUpdates ignore updates to these resources in Consistency and Upgrade tests ImplicitDestroy []string // ImplicitDestroy Remove these resources from the State file to allow implicit destroy ImplicitRequired bool // ImplicitRequired If true the test will fail if the resource fails to be removed from the state file Testing *testing.T `copier:"-"` // Testing The current test object IsUpgradeTest bool // Identifies if current test is an UPGRADE test, used for special processing UpgradeTestSkipped bool // Informs the calling test that conditions were met to skip the upgrade test ExcludeActivityTrackerRegions bool // Will exclude any VPC regions that already contain an Activity Tracker CloudInfoService cloudInfoServiceI // Supply if you need multiple tests to share info service and data // contains filtered or unexported fields }
func TestOptionsDefault ¶
func TestOptionsDefault(originalOptions *TestOptions) *TestOptions
func TestOptionsDefaultWithVars ¶
func TestOptionsDefaultWithVars(originalOptions *TestOptions) *TestOptions
func (*TestOptions) Clone ¶
func (options *TestOptions) Clone() (*TestOptions, error)
Clone makes a deep copy of most fields on the Options object and returns it.
NOTE: options.SshAgent and options.Logger CANNOT be deep copied (e.g., the SshAgent struct contains channels and listeners that can't be meaningfully copied), so the original values are retained.
func (*TestOptions) RunTest ¶
func (options *TestOptions) RunTest() (string, error)
RunTest Runs Test and returns the output as a string for assertions
func (*TestOptions) RunTestConsistency ¶
func (options *TestOptions) RunTestConsistency() (*terraform.PlanStruct, error)
RunTestConsistency Runs Test To check consistency between apply and re-apply, returns the output as string for further assertions
func (*TestOptions) RunTestPlan ¶
func (options *TestOptions) RunTestPlan() (*terraform.PlanStruct, error)
RunTestPlan Runs Test plan and returns the plan as a struct for assertions
func (*TestOptions) RunTestUpgrade ¶
func (options *TestOptions) RunTestUpgrade() (*terraform.PlanStruct, error)
RunTestUpgrade Runs upgrade Test and asserts no resources have been destroyed in the upgrade, returns plan struct for further assertions
type TesthelperTerraformOptions ¶
type TesthelperTerraformOptions struct { CloudInfoService cloudInfoServiceI ExcludeActivityTrackerRegions bool }
TesthelperTerraformOptions options object for optional variables to set primarily used for mocking external services in test cases