Documentation ¶
Index ¶
- Constants
- Variables
- func CheckAllPoliciesHaveGroupID(namedTFResource, expectedGroupID string) resource.TestCheckFunc
- func CheckAllPoliciesHaveSubjectID(namedTFResource, expectedSubjectID string) resource.TestCheckFunc
- func CheckAllResourcesWithTypeDestroyed[T any](resourceType string, f FindBastionZeroAPIObjectFunc[T]) resource.TestCheckFunc
- func CheckExistsAtBastionZero[T any](namedTFResource string, apiObject *T, f FindBastionZeroAPIObjectFunc[T]) resource.TestCheckFunc
- func CheckListOrSetHasElements(namedTFResource, listOrSetAttributeName string) resource.TestCheckFunc
- func CheckResourceAttrIsOneOf(name, key string, values []string) resource.TestCheckFunc
- func CheckResourceDisappears(namedTFResource string, ...) resource.TestCheckFunc
- func CheckTypeSetElemNestedAttrsFromResource(nameFirst string, keys []string, nameSecond string, attr string) resource.TestCheckFunc
- func ConfigCompose(config ...string) string
- func ExpandValuesCheckMapToSingleCheck[T any](resourceName string, apiObject *T, ...) resource.TestCheckFunc
- func FindNAPIObjectsOrSkip[APIObject any, MappedT any](t *testing.T, ...)
- func FindNBzeroTargetsOrSkip(t *testing.T, bzeroTargets ...*targets.BzeroTarget)
- func FindNBzeroTargetsOrSkipAsPolicyTarget(t *testing.T, bzeroTargets ...*policies.Target)
- func FindNClusterTargetsOrSkip(t *testing.T, clusterTargets ...*targets.ClusterTarget)
- func FindNClusterTargetsOrSkipAsPolicyCluster(t *testing.T, clusterTargets ...*policies.Cluster)
- func FindNDACTargetsOrSkip(t *testing.T, dacTargets ...*targets.DynamicAccessConfiguration)
- func FindNDbTargetsOrSkip(t *testing.T, dbTargets ...*targets.DatabaseTarget)
- func FindNDbTargetsOrSkipAsPolicyTarget(t *testing.T, dbTargets ...*policies.Target)
- func FindNEnvironmentsOrSkip(t *testing.T, envs ...*environments.Environment)
- func FindNEnvironmentsOrSkipAsPolicyEnvironment(t *testing.T, envs ...*policies.Environment)
- func FindNGroupsOrSkip(t *testing.T, groups ...*organization.Group)
- func FindNGroupsOrSkipAsPolicyGroup(t *testing.T, groups ...*policies.Group)
- func FindNKubernetesPoliciesOrSkip(t *testing.T, kubernetesPolicies ...*policies.KubernetesPolicy)
- func FindNProxyPoliciesOrSkip(t *testing.T, proxyPolicies ...*policies.ProxyPolicy)
- func FindNServiceAccountsOrSkip(t *testing.T, serviceAccounts ...*serviceaccounts.ServiceAccount)
- func FindNTargetConnectPoliciesOrSkip(t *testing.T, targetConnectPolicies ...*policies.TargetConnectPolicy)
- func FindNUsersOrSkip(t *testing.T, userPointers ...*users.User)
- func FindNUsersOrSkipAsPolicySubject(t *testing.T, subjects ...*policies.Subject)
- func FindNWebTargetsOrSkip(t *testing.T, webTargets ...*targets.WebTarget)
- func ListOrSetCount(resourceState *terraform.ResourceState, listOrSetAttributeName string) (int, error)
- func PreCheck(ctx context.Context, t *testing.T)
- func RandomName(additionalNames ...string) string
- func SafePrettyInt(value *int) string
- func SetEnvironmentVariables(envs map[string]string) func()
- func SkipIfNotInAcceptanceTestMode(t *testing.T)
- func TerraformObjectToString(o types.Object) string
- func ToTerraformStringList(arr []string) string
- type FindBastionZeroAPIObjectFunc
Constants ¶
const RFC3339RegexPattern = `` /* 148-byte string literal not displayed */
const TestNamePrefix = "tf-acc-test-"
TestNamePrefix is a prefix for randomly generated names used during acceptance testing
const UUIDV4RegexPattern = `^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$`
Variables ¶
var ( // APIClient is a BastionZero API client. // // This can be used in testing code for API calls without requiring the use // of saving and referencing specific ProviderFactories instances. // // PreCheck(t) must be called before using this. APIClient *bzapi.Client // TestProtoV6ProviderFactories are used to instantiate a provider during // testing. The factory function will be invoked for every Terraform CLI // command executed to create a provider server to which the CLI can // reattach. TestProtoV6ProviderFactories map[string]func() (tfprotov6.ProviderServer, error) )
Functions ¶
func CheckAllPoliciesHaveGroupID ¶
func CheckAllPoliciesHaveGroupID(namedTFResource, expectedGroupID string) resource.TestCheckFunc
CheckAllPoliciesHaveGroupID checks that all policies have at least one group that matches an expected ID. It is expected that namedTFResource has a nested list/set attribute named "policies" and the container must contain another attribute named "groups" that contains nested group objects
func CheckAllPoliciesHaveSubjectID ¶
func CheckAllPoliciesHaveSubjectID(namedTFResource, expectedSubjectID string) resource.TestCheckFunc
CheckAllPoliciesHaveSubjectID checks that all policies have at least one subject that matches an expected ID. It is expected that namedTFResource has a nested list/set attribute named "policies" and the container must contain another attribute named "subjects" that contains nested subject objects
func CheckAllResourcesWithTypeDestroyed ¶ added in v0.1.1
func CheckAllResourcesWithTypeDestroyed[T any](resourceType string, f FindBastionZeroAPIObjectFunc[T]) resource.TestCheckFunc
CheckAllResourcesWithTypeDestroyed loops through all resources in the Terraform state and verifies that each resource of type resourceType is destroyed (no longer exists at BastionZero). Function f is used to find the API object given the resource's ID (parsed from Terraform state).
func CheckExistsAtBastionZero ¶
func CheckExistsAtBastionZero[T any](namedTFResource string, apiObject *T, f FindBastionZeroAPIObjectFunc[T]) resource.TestCheckFunc
CheckExistsAtBastionZero attempts to load a resource/datasource with name namedTFResource from the TF state and find an API object at BastionZero, using f, with the resource's ID.
The provided pointer is set if there is no error when calling BastionZero. It can be examined to check that what exists at BastionZero matches what is actually set in the TF config/state.
func CheckListOrSetHasElements ¶
func CheckListOrSetHasElements(namedTFResource, listOrSetAttributeName string) resource.TestCheckFunc
CheckListOrSetHasElements attempts to load a resource/datasource with name namedTFResource from the TF state, and then check that the list/set at listOrSetAttributeName has at least 1 element.
func CheckResourceAttrIsOneOf ¶ added in v0.3.0
func CheckResourceAttrIsOneOf(name, key string, values []string) resource.TestCheckFunc
CheckResourceAttrIsOneOf ensures the Terraform state value is equal to one of the supplied values.
func CheckResourceDisappears ¶
func CheckResourceDisappears(namedTFResource string, f func(client *bzapi.Client, ctx context.Context, id string) (*http.Response, error)) resource.TestCheckFunc
CheckResourceDisappears loads namedTFResource from the Terraform state and runs f to delete the API object at BastionZero. The ID passed to f is taken from the state file
func CheckTypeSetElemNestedAttrsFromResource ¶
func CheckTypeSetElemNestedAttrsFromResource(nameFirst string, keys []string, nameSecond string, attr string) resource.TestCheckFunc
CheckTypeSetElemNestedAttrsFromResource ensures a subset map of values is stored in state for the given name (nameSecond) and key (attr) combination of attributes nested under a list or set block. The expected subset map is built by copying one for one the key and value combinations found at nameFirst in the state.
Optionally, copy certain key and value combinations by providing a whitelist of keys. Otherwise, if keys list is empty, it is assumed all key and value pairs should be asserted to exist in one of the nested objects under a list or set block (specified by attr).
func ConfigCompose ¶
ConfigCompose can be called to concatenate multiple strings to build test configurations
func FindNAPIObjectsOrSkip ¶
func FindNAPIObjectsOrSkip[APIObject any, MappedT any]( t *testing.T, f func(client *bzapi.Client, ctx context.Context) ([]APIObject, *http.Response, error), mapF func(apiObject APIObject) MappedT, filterF func(apiObject APIObject) bool, mappedPointers ...*MappedT, )
FindNAPIObjectsOrSkip calls f to find a list of API objects at BastionZero and sets a variadic number (n) of pointers to the first n API objects found. The API object is converted to another type, MappedT, by calling mapF (pass the identity function if you don't want to map).
Additionally, pass filterF if you wish to filter certain API objects from being included as candidates (pass nil if you don't want to filter).
If there are less than n API objects, then the current test is skipped.
func FindNBzeroTargetsOrSkip ¶
func FindNBzeroTargetsOrSkip(t *testing.T, bzeroTargets ...*targets.BzeroTarget)
FindNBzeroTargetsOrSkip lists the Bzero targets in the BastionZero organization and sets bzeroTargets to the first n Bzero targets found. If there are less than n Bzero targets, then the current test is skipped.
If you need the targets mapped as the policy type (policies.Target), use FindNBzeroTargetsOrSkipAsPolicyTarget() instead.
func FindNBzeroTargetsOrSkipAsPolicyTarget ¶
FindNBzeroTargetsOrSkipAsPolicyTarget lists the Bzero targets in the BastionZero organization and sets bzeroTargets to the first n Bzero targets found. If there are less than n Bzero targets, then the current test is skipped.
func FindNClusterTargetsOrSkip ¶
func FindNClusterTargetsOrSkip(t *testing.T, clusterTargets ...*targets.ClusterTarget)
FindNClusterTargetsOrSkip lists the Cluster targets in the BastionZero organization and sets clusterTargets to the first n Cluster targets found. If there are less than n Cluster targets, then the current test is skipped.
If you need the targets mapped as the policy type (policies.Cluster), use FindNClusterTargetsOrSkipAsPolicyCluster() instead.
func FindNClusterTargetsOrSkipAsPolicyCluster ¶
FindNClusterTargetsOrSkipAsPolicyCluster lists the Cluster targets in the BastionZero organization and sets clusterTargets to the first n Cluster targets found. If there are less than n Cluster targets, then the current test is skipped.
func FindNDACTargetsOrSkip ¶
func FindNDACTargetsOrSkip(t *testing.T, dacTargets ...*targets.DynamicAccessConfiguration)
FindNDACTargetsOrSkip lists the DAC targets in the BastionZero organization and sets dacTargets to the first n DAC targets found. If there are less than n DAC targets, then the current test is skipped.
func FindNDbTargetsOrSkip ¶
func FindNDbTargetsOrSkip(t *testing.T, dbTargets ...*targets.DatabaseTarget)
FindNDbTargetsOrSkip lists the Db targets in the BastionZero organization and sets dbTargets to the first n Db targets found. If there are less than n Db targets, then the current test is skipped.
If you need the targets mapped as the policy type (policies.Target), use FindNDbTargetsOrSkipAsPolicyTarget() instead.
func FindNDbTargetsOrSkipAsPolicyTarget ¶
FindNDbTargetsOrSkipAsPolicyTarget lists the Db targets in the BastionZero organization and sets dbTargets to the first n Db targets found. If there are less than n Db targets, then the current test is skipped.
func FindNEnvironmentsOrSkip ¶
func FindNEnvironmentsOrSkip(t *testing.T, envs ...*environments.Environment)
FindNEnvironmentsOrSkip lists the environments in the BastionZero organization and sets envs to the first n environments found. If there are less than n environments, then the current test is skipped.
If you need the environments mapped as the policy type (policies.Environment), use FindNEnvironmentsOrSkipAsPolicyEnvironment() instead.
func FindNEnvironmentsOrSkipAsPolicyEnvironment ¶ added in v0.3.0
func FindNEnvironmentsOrSkipAsPolicyEnvironment(t *testing.T, envs ...*policies.Environment)
FindNEnvironmentsOrSkipAsPolicyEnvironment lists the environments in the BastionZero organization and sets envs to the first n environments found. If there are less than n environments, then the current test is skipped.
func FindNGroupsOrSkip ¶
func FindNGroupsOrSkip(t *testing.T, groups ...*organization.Group)
FindNGroupsOrSkip lists the groups in the BastionZero organization and sets groups to the first n groups found. If there are less than n groups, then the current test is skipped.
If you need the groups mapped as the policy type (policies.Group), use FindNGroupsOrSkipAsPolicyGroup() instead.
func FindNGroupsOrSkipAsPolicyGroup ¶
FindNGroupsOrSkipAsPolicyGroup lists the groups in the BastionZero organization and sets groups to the first n groups found. If there are less than n groups, then the current test is skipped.
func FindNKubernetesPoliciesOrSkip ¶
func FindNKubernetesPoliciesOrSkip(t *testing.T, kubernetesPolicies ...*policies.KubernetesPolicy)
FindNKubernetesPoliciesOrSkip lists the Kubernetes policies in the BastionZero organization and sets kubernetesPolicies to the first n Kubernetes policies found. If there are less than n Kubernetes policies, then the current test is skipped.
func FindNProxyPoliciesOrSkip ¶
func FindNProxyPoliciesOrSkip(t *testing.T, proxyPolicies ...*policies.ProxyPolicy)
FindNProxyPoliciesOrSkip lists the proxy policies in the BastionZero organization and sets proxyPolicies to the first n proxy policies found. If there are less than n proxy policies, then the current test is skipped.
func FindNServiceAccountsOrSkip ¶
func FindNServiceAccountsOrSkip(t *testing.T, serviceAccounts ...*serviceaccounts.ServiceAccount)
FindNServiceAccountsOrSkip lists the service accounts in the BastionZero organization and sets serviceAccounts to the first n service accounts found. If there are less than n service accounts, then the current test is skipped.
func FindNTargetConnectPoliciesOrSkip ¶
func FindNTargetConnectPoliciesOrSkip(t *testing.T, targetConnectPolicies ...*policies.TargetConnectPolicy)
FindNTargetConnectPoliciesOrSkip lists the target connect policies in the BastionZero organization and sets targetConnectPolicies to the first n target connect policies found. If there are less than n target connect policies, then the current test is skipped.
func FindNUsersOrSkip ¶
FindNUsersOrSkip lists the users in the BastionZero organization and sets userPointers to the first n users found. If there are less than n users, then the current test is skipped.
If you need the users mapped as the policy type (policies.Subject), use FindNUsersOrSkipAsPolicySubject() instead.
func FindNUsersOrSkipAsPolicySubject ¶
FindNUsersOrSkipAsPolicySubject lists the users in the BastionZero organization and sets subjects to the first n subjects found. If there are less than n users, then the current test is skipped.
func FindNWebTargetsOrSkip ¶
FindNWebTargetsOrSkip lists the Web targets in the BastionZero organization and sets webTargets to the first n Web targets found. If there are less than n Web targets, then the current test is skipped.
func ListOrSetCount ¶
func ListOrSetCount(resourceState *terraform.ResourceState, listOrSetAttributeName string) (int, error)
ListOrSetCount returns the number of elements in a list or set attribute
func PreCheck ¶
PreCheck verifies and sets required provider testing configuration
PreCheck makes assertions that must hold true in order to run an acceptance test. The test fails immediately if any of these assertions fails.
This PreCheck function should be present in every acceptance test. It allows test configurations to omit a provider configuration and ensures testing functions that attempt to call BastionZero APIs directly via APIClient are previously configured.
func RandomName ¶
RandomName creates a random name suitable for named BastionZero API objects that are created during acceptance tests.
func SafePrettyInt ¶ added in v0.3.0
func SetEnvironmentVariables ¶
SetEnvironmentVariables sets environment variables and provides a cleanup function to reset the modified environment variables back to their original value.
Source: https://dev.to/arxeiss/auto-reset-environment-variables-when-testing-in-go-5ec
func SkipIfNotInAcceptanceTestMode ¶
SkipIfNotInAcceptanceTestMode performs the same check that the terraform-plugin-testing library performs to see if the test should be executed or not. Its logic is duplicated here, so we can call it ourselves before the Test() block in case there are additional things that need to be done that cannot be done in PreConfig() or PreCheck()
func TerraformObjectToString ¶ added in v0.3.0
TerraformObjectToString returns a human-readable representation of the Object value that can be used in Terraform configurations. This function is equivalent to basetypes.Object.String() except that null object attributes are omitted from the final string.