testsacc

package
v0.15.1 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2023 License: MPL-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	KeyValueStore = &map[string]any{}
)

Functions

func GenerateTestChecks added in v0.12.0

func GenerateTestChecks(ctx context.Context, tacc TestACC, resourceName string, testName TestName) []resource.TestCheckFunc

GenerateTestChecks Generate the checks for a specific test.

func GenerateTests

func GenerateTests(tacc TestACC) []resource.TestStep

GenerateTests generates the acceptance tests for the resource under test.

func GetValueFromTemplate added in v0.11.0

func GetValueFromTemplate(resourceName, key string) string

GetValueFromTemplate returns the value of the given key from the key-value store.

func ImportStateIDBuilder

func ImportStateIDBuilder(resourceName string, attributeNames []string) resource.ImportStateIdFunc

ImportStateIDBuilder is a function that can be used to dynamically generate the ID for the ImportState tests. It is sent the state, which can be checked to derive the attributes necessary and generate the string in the desired format. Specifie the list of attribute names to use to build the ID. Example of use: []string{"vdc_name", "edgegateway_name"} => "vdcExample.edgegatewayExample".

Types

type DependenciesConfigResponse added in v0.15.0

type DependenciesConfigResponse []func() TFData

func (*DependenciesConfigResponse) Append added in v0.15.0

func (d *DependenciesConfigResponse) Append(tf func() TFData)

* DependenciesConfigResponse Append appends the given dependencies config to the current one.

type ListOfDependencies added in v0.11.0

type ListOfDependencies []ResourceName

func (*ListOfDependencies) Append added in v0.11.0

func (l *ListOfDependencies) Append(resourceName ResourceName)

* ListOfDependencies Append appends the given dependency to the list of dependencies. resourceName is a concatenation of the resource name and the name. For example, "cloudavenue_catalog.example".

func (*ListOfDependencies) Exists added in v0.11.0

func (l *ListOfDependencies) Exists(resourceName ResourceName) bool

Exists checks if the given dependency exists in the list of dependencies. resourceName is a concatenation of the resource name and the name. For example, "cloudavenue_catalog.example".

type ResourceName added in v0.11.0

type ResourceName string

func (ResourceName) String added in v0.11.0

func (r ResourceName) String() string

* ResourceName String returns the string representation of the ResourceName.

type TFACCLog added in v0.15.0

type TFACCLog struct {
	Level string `env:"LEVEL,default=info"`
}

TODO : Add TFACCLog management.

type TFAdvanced added in v0.12.0

type TFAdvanced struct {
	// PreConfig is called before the Config is applied to perform any per-step
	// setup that needs to happen. This is called regardless of "test mode"
	// below.
	PreConfig func()

	// Taint is a list of resource addresses to taint prior to the execution of
	// the step. Be sure to only include this at a step where the referenced
	// address will be present in state, as it will fail the test if the resource
	// is missing.
	//
	// This option is ignored on ImportState tests, and currently only works for
	// resources in the root module path.
	Taint []string

	// Destroy will create a destroy plan if set to true.
	Destroy bool

	// ExpectNonEmptyPlan can be set to true for specific types of tests that are
	// looking to verify that a diff occurs
	ExpectNonEmptyPlan bool

	// ExpectError allows the construction of test cases that we expect to fail
	// with an error. The specified regexp must match against the error for the
	// test to pass.
	ExpectError *regexp.Regexp

	// PlanOnly can be set to only run `plan` with this configuration, and not
	// actually apply it. This is useful for ensuring config changes result in
	// no-op plans
	PlanOnly bool

	// PreventDiskCleanup can be set to true for testing terraform modules which
	// require access to disk at runtime. Note that this will leave files in the
	// temp folder
	PreventDiskCleanup bool

	// PreventPostDestroyRefresh can be set to true for cases where data sources
	// are tested alongside real resources
	PreventPostDestroyRefresh bool
}

func (*TFAdvanced) IsEmpty added in v0.12.0

func (t *TFAdvanced) IsEmpty() bool

IsEmpty returns true if the TFAdvanced is empty.

type TFConfig

type TFConfig struct {
	// Checks is a Terraform checks to run for checking the resource under test.
	// If EnableAutoCheck is true, these checks will be automatically added to the test.
	// If EnableAutoCheck is false, these checks will be the only checks run for the test.
	Checks []resource.TestCheckFunc

	// TFCongig is the Terraform configuration to use for the test.
	TFConfig TFData

	// TFAdvanced is the Terraform advanced configuration to use for the test.
	TFAdvanced TFAdvanced
}

func (TFConfig) Generate

func (t TFConfig) Generate(_ context.Context, dependencies TFData) string

Generate creates the Terraform configuration for the resource under test. It returns the Terraform configuration as a string. Concatenate the dependencies config and the resource config.

type TFData

type TFData string

func GenerateFromTemplate added in v0.11.0

func GenerateFromTemplate(resourceName, templateData string) TFData

GenerateFromTemplate generates the Terraform configuration from the given template. The template can contain placeholders that will be replaced by the given values.

Who to use:

resource "cloudavenue_catalog" "example" {
	name             = {{ get . "name" }}
	description      = {{ generate . "description" "longString"}}
	delete_recursive = true
	delete_force     = true
}

Available functions in the template:

  • generate: generates a random string and stores it in the key-value store. Generate accepts an optional argument that specifies the format of the random string (available formats: "shortString", "longString"). Default format is "shortString".
  • get: returns the value of the given key from the key-value store.

func (*TFData) Append

func (t *TFData) Append(tf TFData)

Append appends the given Terraform configuration to the current one.

func (*TFData) AppendWithoutResourceName added in v0.11.0

func (t *TFData) AppendWithoutResourceName(tf TFData)

AppendWithoutResourceName appends the given Terraform configuration to the current one.

func (TFData) Get

func (t TFData) Get() string

Get returns the Terraform configuration as a string.

func (*TFData) IsEmpty added in v0.11.0

func (t *TFData) IsEmpty() bool

is empty.

func (*TFData) Set

func (t *TFData) Set(s string)

Set sets the Terraform configuration to the given string.

func (TFData) String

func (t TFData) String() string

String returns the Terraform configuration as a string.

type TFImport

type TFImport struct {
	// ImportStateId is the ID to perform an ImportState operation with.
	// This is optional. If it isn't set, then the resource ID is automatically
	// determined by inspecting the state for ResourceName's ID.
	ImportStateID string

	// ImportStateIdFunc is a function that can be used to dynamically generate
	// the ID for the ImportState tests. It is sent the state, which can be
	// checked to derive the attributes necessary and generate the string in the
	// desired format.
	ImportStateIDFunc resource.ImportStateIdFunc

	// ImportStateIDBuilder is a function that can be used to dynamically generate
	// the ID for the ImportState tests. It is sent the state, which can be
	// checked to derive the attributes necessary and generate the string in the
	// desired format.
	// Specifie the list of attribute names to use to build the ID.
	// Example of use: []string{"vdc_name", "edgegateway_name"} => "vdcExample.edgegatewayExample"
	ImportStateIDBuilder []string

	// ImportStateVerifyIgnore is a list of prefixes of fields that should
	// not be verified to be equal. These can be set to ephemeral fields or
	// fields that can't be refreshed and don't matter.
	ImportStateVerifyIgnore []string

	// ImportStatePersist, if true, will update the persisted state with the
	// state generated by the import operation (i.e., terraform import). When
	// false (default) the state generated by the import operation is discarded
	// at the end of the test step that is verifying import behavior.
	ImportStatePersist bool

	// ImportStateVerify, if true, will also check that the state values
	// that are finally put into the state after import match for all the
	// IDs returned by the Import.
	ImportStateVerify bool

	// ImportState, if true, will test the functionality of ImportState
	// by importing the resource with ID of that resource.
	ImportState bool
}

type Test

type Test struct {
	// CommonChecks is a list of common Terraform checks applied to all tests.
	CommonChecks []resource.TestCheckFunc

	// Create returns the Terraform configuration to use for the test.
	// This should be a valid Terraform configuration that can be used to create, update, and destroy resources.
	Create TFConfig

	// Update returns the Terraform configurations to use for the update test.
	// This should be a valid Terraform configuration that can be used to update the resource under test.
	Updates []TFConfig

	// Import returns the Terraform configurations to use for the import test.
	Imports []TFImport

	// Destroy will create a destroy plan if set to true.
	Destroy bool

	// CacheDependenciesConfig is used to cache the dependencies config.
	CacheDependenciesConfig TFData
	// contains filtered or unexported fields
}

func (*Test) ComputeDependenciesConfig added in v0.15.0

func (t *Test) ComputeDependenciesConfig(testACC TestACC)

Compute Dependencies config.

func (Test) GenerateCheckWithCommonChecks

func (t Test) GenerateCheckWithCommonChecks() []resource.TestCheckFunc

GenerateCheckWithCommonChecks concatenates the common checks and the specific checks.

func (Test) GenerateSteps

func (t Test) GenerateSteps(ctx context.Context, testName TestName, testACC TestACC) (steps []resource.TestStep)

GenerateSteps generates the structure of the acceptance tests.

type TestACC

type TestACC interface {
	// GetResourceName returns the name of the resource under test.
	GetResourceName() string

	// DependenciesConfig returns the Terraform configuration used to create any dependencies of the resource under test.
	DependenciesConfig() DependenciesConfigResponse

	// Tests returns the acceptance tests to run for the resource under test.
	// resourceName is a concatenation of the resource name and the example name. For example, "cloudavenue_catalog.example".
	Tests(context.Context) map[TestName]func(ctx context.Context, resourceName string) Test
}

type TestName

type TestName string

func (TestName) ComputeResourceName

func (e TestName) ComputeResourceName(resourceName string) string

ComputeResourceName returns the name of the resource under test. Return cloudavenue_<resource_name>.<example_name>.

func (TestName) Get

func (e TestName) Get() string

* TestName Get return the name of the example formatted as a lower camel case string.

func (TestName) String

func (e TestName) String() string

String string representation of the example name.

Jump to

Keyboard shortcuts

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