Documentation ¶
Index ¶
- Constants
- func GetTerraformDir(t *testing.T, path string, isParallel bool) (string, error)
- func SetupTerraformDirForParallelism(t *testing.T, tfDir string) (string, error)
- type Client
- type Config
- type JSONPathTestCases
- type OptFn
- func WithAWS(region string) OptFn
- func WithEnvVars(envVars map[string]string) OptFn
- func WithParallel() OptFn
- func WithPlanFile(planFile string) OptFn
- func WithRetry(retryableErrors map[string]string, timeBetweenRetries time.Duration, ...) OptFn
- func WithScannedTFVars(workdir, fixturesDir string) OptFn
- func WithVarFiles(workdir string, varFiles ...string) OptFn
- func WithVars(vars map[string]interface{}) OptFn
- type Options
- type Stage
- type StageClient
- func (c *StageClient) ApplyStage(t *testing.T, options *terraform.Options)
- func (c *StageClient) CheckResourcesChanges(t *testing.T, options *terraform.Options, resources []string, ...)
- func (c *StageClient) DestroyStage(t *testing.T, options *terraform.Options)
- func (c *StageClient) PlanAndAssertJSONWithJSONPath(t *testing.T, options *terraform.Options, testCases []JSONPathTestCases)
- func (c *StageClient) PlanStage(t *testing.T, options *terraform.Options)
- func (c *StageClient) PlanStageExpectedNoChanges(t *testing.T, options *terraform.Options)
- func (c *StageClient) PlanStageWithAnySortOfChanges(t *testing.T, options *terraform.Options)
- func (c *StageClient) PlanStageWithDetailedExpectedChanges(t *testing.T, options *terraform.Options, ...)
- func (c *StageClient) PlanStageWithExpectedChanges(t *testing.T, options *terraform.Options, expectedChanges int)
- func (c *StageClient) PlanWithResourcesExpectedToBeCreated(t *testing.T, options *terraform.Options, resources []string)
- func (c *StageClient) PlanWithResourcesExpectedToBeDeleted(t *testing.T, options *terraform.Options, resources []string)
- func (c *StageClient) PlanWithResourcesExpectedToBeUpdated(t *testing.T, options *terraform.Options, resources []string)
- func (c *StageClient) PlanWithSpecificResourcesThatShouldNotChange(t *testing.T, options *terraform.Options, resources []string)
- func (c *StageClient) PlanWithSpecificResourcesThatWillChange(t *testing.T, options *terraform.Options, resources []string)
- func (c *StageClient) PlanWithSpecificVariableValueToExpect(t *testing.T, options *terraform.Options, variable, expectedValue string)
- type TestType
Constants ¶
const ( ShouldContain = iota ShouldNOTContain ShouldBeEqual )
const DefaultPlanOutput = "plan.out"
Variables ¶
This section is empty.
Functions ¶
func GetTerraformDir ¶ added in v0.0.6
GetTerraformDir returns the Terraform directory path for the scenario. If the scenario is running in parallel, it sets up the Terraform directory for parallelism.
Parameters:
- t: The testing instance.
- path: The path to the Terraform directory.
- isParallel: A boolean flag indicating whether the scenario is running in parallel.
Returns:
- string: The path to the Terraform directory (or a temporary directory if running in parallel).
- error: An error if the Terraform directory is not valid or if parallel setup fails.
Example:
terraformDir, err := GetTerraformDir(t, "/path/to/terraform/dir", true) if err != nil { t.Fatalf("Error getting Terraform directory: %v", err) } fmt.Printf("Terraform directory: %s\n", terraformDir)
func SetupTerraformDirForParallelism ¶ added in v0.0.6
SetupTerraformDirForParallelism sets up the Terraform directory for parallelism by copying the specified Terraform directory to a temporary directory. This ensures that parallel tests do not interfere with each other.
Parameters:
- t: The testing instance. This parameter is required.
- tfDir: The path to the Terraform directory. This parameter is required.
Returns:
- string: The path to the temporary directory containing the copied Terraform directory.
- error: An error if the setup fails.
Example:
tempDir, err := SetupTerraformDirForParallelism(t, "/path/to/terraform/dir") if err != nil { t.Fatalf("Error setting up Terraform directory for parallelism: %v", err) } fmt.Printf("Temporary Terraform directory: %s\n", tempDir)
Types ¶
type Client ¶
type Client struct { Stg *StageClient // contains filtered or unexported fields }
Client represents a Terraform client for managing Terraform operations.
func New ¶
New creates a new Terraform Client with default retryable errors and saves it to the workdir. This is a wrapper around terraform.WithDefaultRetryableErrors.
Parameters:
- t: The testing instance.
- workdir: The working directory.
Returns:
- *Client: A new Client instance.
- error: An error if the Client could not be created.
func NewWithOptions ¶
NewWithOptions creates a new Client with the specified options.
Parameters:
- t: The testing instance.
- workdir: The working directory.
- opts: A list of option functions to modify the options.
Returns:
- *Client: A new Client instance.
- error: An error if the Client could not be created.
func (*Client) GetAWS ¶
func (c *Client) GetAWS() cloudprovider.AWSAdapter
GetAWS returns the AWS Cloud Provider (Client) for the client.
Returns:
- cloudprovider.AWSAdapter: The AWS Cloud Provider (Client).
func (*Client) GetTerraformOptions ¶
GetTerraformOptions returns the Terraform options for the client. If the options are not set, it returns an empty Terraform options object.
Returns:
- *terraform.Options: The Terraform options.
type Config ¶
type Config interface { GetTerraformOptions() *terraform.Options GetAWS() cloudprovider.AWSAdapter }
Config defines an interface for obtaining Terraform options and AWS configuration.
type JSONPathTestCases ¶ added in v0.0.11
type JSONPathTestCases struct { TestName string ExpectedValue interface{} JSONPathToCompare string AllowDifferentType bool TestType TestType }
JSONPathTestCases represents the test cases for JSON path assertions.
type OptFn ¶
OptFn is a function type used to modify Options.
func WithAWS ¶
WithAWS enables the AWS Cloud Provider (Client) for the options and sets the AWS region.
Parameters:
- region: The AWS region. If not set, it defaults to "us-west-2".
Returns:
- OptFn: A function to modify the options.
func WithEnvVars ¶ added in v0.0.15
WithEnvVars sets the environment variables for the options.
Parameters:
- envVars: A map of environment variables.
Returns:
- OptFn: A function to modify the options.
func WithParallel ¶ added in v0.0.6
func WithParallel() OptFn
WithParallel enables parallelism for the options.
Returns:
- OptFn: A function to modify the options.
func WithPlanFile ¶ added in v0.0.16
WithPlanFile sets the plan file path for the options.
Parameters:
- planFile: The path to the plan file.
Returns:
- OptFn: A function to modify the options.
func WithRetry ¶ added in v0.0.7
func WithRetry(retryableErrors map[string]string, timeBetweenRetries time.Duration, maxRetries int) OptFn
WithRetry sets the retry options for the Terraform operations.
Parameters:
- retryableErrors: A map of retryable errors.
- timeBetweenRetries: The duration to wait between retries.
- maxRetries: The maximum number of retries.
Returns:
- OptFn: A function to modify the options.
func WithScannedTFVars ¶ added in v0.0.8
WithScannedTFVars scans the working directory and fixtures directory for Terraform variable files and sets them for the options.
Parameters:
- workdir: The working directory.
- fixturesDir: The fixtures directory.
Returns:
- OptFn: A function to modify the options.
func WithVarFiles ¶
WithVarFiles sets the variable files for the options.
Parameters:
- workdir: The working directory.
- varFiles: A list of variable file names.
Returns:
- OptFn: A function to modify the options.
type Options ¶
type Options struct {
// contains filtered or unexported fields
}
Options represents the configuration options for a Terraform scenario.
type Stage ¶
type Stage interface { DestroyStage(t *testing.T, options *terraform.Options) PlanStage(t *testing.T, options *terraform.Options) ApplyStage(t *testing.T, options *terraform.Options) PlanStageWithExpectedChanges(t *testing.T, options *terraform.Options, expectedChanges int) PlanStageWithDetailedExpectedChanges(t *testing.T, options *terraform.Options, expectedAdds, expectedDeletes, expectedUpdates int) PlanStageWithAnySortOfChanges(t *testing.T, options *terraform.Options) PlanStageExpectedNoChanges(t *testing.T, options *terraform.Options) PlanWithSpecificResourcesThatWillChange(t *testing.T, options *terraform.Options, resources []string) PlanWithSpecificResourcesThatShouldNotChange(t *testing.T, options *terraform.Options, resources []string) PlanWithResourcesExpectedToBeCreated(t *testing.T, options *terraform.Options, resources []string) PlanWithResourcesExpectedToBeDeleted(t *testing.T, options *terraform.Options, resources []string) PlanWithResourcesExpectedToBeUpdated(t *testing.T, options *terraform.Options, resources []string) PlanWithSpecificVariableValueToExpect(t *testing.T, options *terraform.Options, variable, value string) PlanAndAssertJSONWithJSONPath(t *testing.T, options *terraform.Options, testCases []JSONPathTestCases) }
Stage defines an interface for managing Terraform stages.
type StageClient ¶
type StageClient struct{}
StageClient represents a client for managing Terraform stages.
func (*StageClient) ApplyStage ¶
func (c *StageClient) ApplyStage(t *testing.T, options *terraform.Options)
ApplyStage applies the Terraform stage.
Parameters:
- t: The testing instance.
- options: The Terraform options.
func (*StageClient) CheckResourcesChanges ¶
func (c *StageClient) CheckResourcesChanges(t *testing.T, options *terraform.Options, resources []string, check func(tfjson.Actions) bool, failMsg string)
CheckResourcesChanges checks if the specified resources have the expected changes The check function is used to determine if the resource has the expected change
func (*StageClient) DestroyStage ¶
func (c *StageClient) DestroyStage(t *testing.T, options *terraform.Options)
DestroyStage destroys the Terraform stage.
Parameters:
- t: The testing instance.
- options: The Terraform options.
func (*StageClient) PlanAndAssertJSONWithJSONPath ¶ added in v0.0.11
func (c *StageClient) PlanAndAssertJSONWithJSONPath(t *testing.T, options *terraform.Options, testCases []JSONPathTestCases)
PlanAndAssertJSONWithJSONPath performs JSON path planning and assertion in Go testing.
Parameters:
- t: The testing object.
- options: The Terraform options.
- testCases: An array of JSON path test cases.
func (*StageClient) PlanStage ¶
func (c *StageClient) PlanStage(t *testing.T, options *terraform.Options)
PlanStage plans the Terraform stage.
Parameters:
- t: The testing instance.
- options: The Terraform options.
func (*StageClient) PlanStageExpectedNoChanges ¶
func (c *StageClient) PlanStageExpectedNoChanges(t *testing.T, options *terraform.Options)
PlanStageExpectedNoChanges plans the Terraform stage and expects no changes.
Parameters:
- t: The testing instance.
- options: The Terraform options.
func (*StageClient) PlanStageWithAnySortOfChanges ¶
func (c *StageClient) PlanStageWithAnySortOfChanges(t *testing.T, options *terraform.Options)
PlanStageWithAnySortOfChanges plans the Terraform stage and checks for any sort of changes.
Parameters:
- t: The testing instance.
- options: The Terraform options.
func (*StageClient) PlanStageWithDetailedExpectedChanges ¶
func (c *StageClient) PlanStageWithDetailedExpectedChanges(t *testing.T, options *terraform.Options, expectedAdds, expectedDeletes, expectedUpdates int)
PlanStageWithDetailedExpectedChanges plans the Terraform stage and checks for the expected number of additions, deletions, and updates.
Parameters:
- t: The testing instance.
- options: The Terraform options.
- expectedAdds: The expected number of additions.
- expectedDeletes: The expected number of deletions.
- expectedUpdates: The expected number of updates.
func (*StageClient) PlanStageWithExpectedChanges ¶
func (c *StageClient) PlanStageWithExpectedChanges(t *testing.T, options *terraform.Options, expectedChanges int)
PlanStageWithExpectedChanges plans the Terraform stage and checks for the expected number of changes.
Parameters:
- t: The testing instance.
- options: The Terraform options.
- expectedChanges: The expected number of changes.
func (*StageClient) PlanWithResourcesExpectedToBeCreated ¶
func (c *StageClient) PlanWithResourcesExpectedToBeCreated(t *testing.T, options *terraform.Options, resources []string)
PlanWithResourcesExpectedToBeCreated plans the Terraform stage and checks that the specified resources are expected to be created.
Parameters:
- t: The testing instance.
- options: The Terraform options.
- resources: A list of resource addresses that are expected to be created.
func (*StageClient) PlanWithResourcesExpectedToBeDeleted ¶
func (c *StageClient) PlanWithResourcesExpectedToBeDeleted(t *testing.T, options *terraform.Options, resources []string)
PlanWithResourcesExpectedToBeDeleted plans the Terraform stage and checks that the specified resources are expected to be deleted.
Parameters:
- t: The testing instance.
- options: The Terraform options.
- resources: A list of resource addresses that are expected to be deleted.
func (*StageClient) PlanWithResourcesExpectedToBeUpdated ¶
func (c *StageClient) PlanWithResourcesExpectedToBeUpdated(t *testing.T, options *terraform.Options, resources []string)
PlanWithResourcesExpectedToBeUpdated plans the Terraform stage and checks that the specified resources are expected to be updated.
Parameters:
- t: The testing instance.
- options: The Terraform options.
- resources: A list of resource addresses that are expected to be updated.
func (*StageClient) PlanWithSpecificResourcesThatShouldNotChange ¶ added in v0.0.17
func (c *StageClient) PlanWithSpecificResourcesThatShouldNotChange(t *testing.T, options *terraform.Options, resources []string)
PlanWithSpecificResourcesThatShouldNotChange plans the Terraform stage and checks that the specified resources should not change.
Parameters:
- t: The testing instance.
- options: The Terraform options.
- resources: A list of resource addresses that are expected not to change.
func (*StageClient) PlanWithSpecificResourcesThatWillChange ¶
func (c *StageClient) PlanWithSpecificResourcesThatWillChange(t *testing.T, options *terraform.Options, resources []string)
PlanWithSpecificResourcesThatWillChange plans the Terraform stage and checks that the specified resources will change.
Parameters:
- t: The testing instance.
- options: The Terraform options.
- resources: A list of resource addresses that are expected to change.
func (*StageClient) PlanWithSpecificVariableValueToExpect ¶
func (c *StageClient) PlanWithSpecificVariableValueToExpect(t *testing.T, options *terraform.Options, variable, expectedValue string)
PlanWithSpecificVariableValueToExpect plans the Terraform stage and checks that the specified variable has the expected value.
Parameters:
- t: The testing instance.
- options: The Terraform options.
- variable: The name of the variable to check.
- expectedValue: The expected value of the variable.