acctest

package
v0.0.0-...-7000f67 Latest Latest
Warning

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

Go to latest
Published: Sep 6, 2023 License: MPL-2.0 Imports: 52 Imported by: 0

Documentation

Overview

Copyright (c) HashiCorp, Inc. SPDX-License-Identifier: MPL-2.0

Copyright (c) HashiCorp, Inc. SPDX-License-Identifier: MPL-2.0

Copyright (c) HashiCorp, Inc. SPDX-License-Identifier: MPL-2.0

Copyright (c) HashiCorp, Inc. SPDX-License-Identifier: MPL-2.0

Copyright (c) HashiCorp, Inc. SPDX-License-Identifier: MPL-2.0

Copyright (c) HashiCorp, Inc. SPDX-License-Identifier: MPL-2.0

Index

Constants

View Source
const SharedTestADDomainPrefix = "tf-bootstrap-ad"
View Source
const SharedTestNetworkPrefix = "tf-bootstrap-net-"
View Source
const SharedTestSQLInstanceNamePrefix = "tf-bootstrap-"

SQL Instance names are not reusable for a week after deletion

Variables

View Source
var SharedCryptoKey = map[string]string{
	"ENCRYPT_DECRYPT":    "tftest-shared-key-1",
	"ASYMMETRIC_SIGN":    "tftest-shared-sign-key-1",
	"ASYMMETRIC_DECRYPT": "tftest-shared-decrypt-key-1",
}
View Source
var SharedKeyRing = "tftest-shared-keyring-1"
View Source
var SharedServicePerimeterProjectPrefix = "tf-bootstrap-sp-"
View Source
var TestAccProviders map[string]*schema.Provider

Functions

func AccTestPreCheck

func AccTestPreCheck(t *testing.T)

func BootstrapAllPSARole

func BootstrapAllPSARole(t *testing.T, prefix string, agentNames []string, role string) bool

BootstrapAllPSARole is a version of BootstrapAllPSARoles for granting a single role to multiple service agents.

func BootstrapAllPSARoles

func BootstrapAllPSARoles(t *testing.T, prefix string, agentNames, roles []string) bool

BootstrapAllPSARoles ensures that the given project's IAM policy grants the given service agents the given roles. prefix is usually "service-" and indicates the service agent should have the given prefix before the project number. This is important to bootstrap because using iam policy resources means that deleting them removes permissions for concurrent tests. Return whether the bindings changed.

func BootstrapConfig

func BootstrapConfig(t *testing.T) *transport_tpg.Config

BootstrapConfig returns a Config pulled from the environment.

func BootstrapNetworkAttachment

func BootstrapNetworkAttachment(t *testing.T, networkAttachmentName string, subnetName string) string

func BootstrapPSARole

func BootstrapPSARole(t *testing.T, prefix, agentName, role string) bool

BootstrapPSARole is a simplified version of BootstrapPSARoles for granting a single role to a single service agent.

func BootstrapPSARoles

func BootstrapPSARoles(t *testing.T, prefix, agentName string, roles []string) bool

BootstrapPSARoles is a version of BootstrapAllPSARoles for granting roles to a single service agent.

func BootstrapProject

func BootstrapProject(t *testing.T, projectIDPrefix, billingAccount string, services []string) *cloudresourcemanager.Project

BootstrapProject will create or get a project named "<projectIDPrefix><projectIDSuffix>" that will persist across test runs, where projectIDSuffix is based off of getTestProjectFromEnv(). The reason for the naming is to isolate bootstrapped projects by test environment. Given the existing projects being used by our team, the prefix provided to this function can be no longer than 18 characters.

func BootstrapServiceAccount

func BootstrapServiceAccount(t *testing.T, project, testRunner string) string

func BootstrapServicePerimeterProjects

func BootstrapServicePerimeterProjects(t *testing.T, desiredProjects int) []*cloudresourcemanager.Project

func BootstrapSharedCaPoolInLocation

func BootstrapSharedCaPoolInLocation(t *testing.T, location string) string

func BootstrapSharedSQLInstanceBackupRun

func BootstrapSharedSQLInstanceBackupRun(t *testing.T) string

BootstrapSharedSQLInstanceBackupRun will return a shared SQL db instance that has a backup created for it.

func BootstrapSharedTestADDomain

func BootstrapSharedTestADDomain(t *testing.T, testId string, networkName string) string

func BootstrapSharedTestNetwork

func BootstrapSharedTestNetwork(t *testing.T, testId string) string

BootstrapSharedTestNetwork will return a persistent compute network for a test or set of tests.

Resources like service_networking_connection use a consumer network and create a complementing tenant network which we don't control. These tenant networks never get cleaned up and they can accumulate to the point where a limit is reached for the organization. By reusing a consumer network across test runs, we can reduce the number of tenant networks that are needed. See b/146351146 for more context.

testId specifies the test for which a shared network is used/initialized. Note that if the network is being used for a service_networking_connection, the same testId should generally not be used across tests, to avoid race conditions where multiple tests attempt to modify the connection at once.

Returns the name of a network, creating it if it hasn't been created in the test project.

func BootstrapSubnet

func BootstrapSubnet(t *testing.T, subnetName string, networkName string) string

func CheckDataSourceStateMatchesResourceState

func CheckDataSourceStateMatchesResourceState(dataSourceName, resourceName string) func(*terraform.State) error

func CheckDataSourceStateMatchesResourceStateWithIgnores

func CheckDataSourceStateMatchesResourceStateWithIgnores(dataSourceName, resourceName string, ignoreFields map[string]struct{}) func(*terraform.State) error

func CreateZIPArchiveForCloudFunctionSource

func CreateZIPArchiveForCloudFunctionSource(t *testing.T, sourcePath string) string

func GenerateFakeCredentialsJson

func GenerateFakeCredentialsJson(testId string) string

Returns a fake credentials JSON string with the client_email set to a test-specific value

func GetFwTestProvider

func GetFwTestProvider(t *testing.T) *frameworkTestProvider

func GetSDKProvider

func GetSDKProvider(testName string) *schema.Provider

GetSDKProvider gets the SDK provider with an overwritten configure function to be called by MuxedProviders

func GetTestProject

func GetTestProject(is *terraform.InstanceState, config *transport_tpg.Config) (string, error)

GetTestProject has the same logic as the provider's GetProject, to be used in tests.

func GetTestRegion

func GetTestRegion(is *terraform.InstanceState, config *transport_tpg.Config) (string, error)

GetTestRegion has the same logic as the provider's GetRegion, to be used in tests.

func GoogleProviderConfig

func GoogleProviderConfig(t *testing.T) *transport_tpg.Config

func HandleVCRConfiguration

func HandleVCRConfiguration(ctx context.Context, testName string, rndTripper http.RoundTripper, pollInterval time.Duration) (time.Duration, http.RoundTripper, fwDiags.Diagnostics)

func IsVcrEnabled

func IsVcrEnabled() bool

func MuxedProviders

func MuxedProviders(testName string) (func() tfprotov5.ProviderServer, error)

MuxedProviders returns the correct test provider (between the sdk version or the framework version)

func NewFrameworkTestProvider

func NewFrameworkTestProvider(testName string) *frameworkTestProvider

func Nprintf

func Nprintf(format string, params map[string]interface{}) string

This is a Printf sibling (Nprintf; Named Printf), which handles strings like Nprintf("Hello %{target}!", map[string]interface{}{"target":"world"}) == "Hello world!". This is particularly useful for generated tests, where we don't want to use Printf, since that would require us to generate a very particular ordering of arguments.

func ProtoV5ProviderBetaFactories

func ProtoV5ProviderBetaFactories(t *testing.T) map[string]func() (tfprotov5.ProviderServer, error)

ProtoV5ProviderBetaFactories returns the same as ProtoV5ProviderFactories only the provider is mapped with "google-beta" to ensure that registry examples use `google-beta` if the example is versioned as beta; normal beta tests should continue to use ProtoV5ProviderFactories

func ProtoV5ProviderFactories

func ProtoV5ProviderFactories(t *testing.T) map[string]func() (tfprotov5.ProviderServer, error)

ProtoV5ProviderFactories returns a muxed ProviderServer that uses the provider code from this repo (SDK and plugin-framework). Used to set ProtoV5ProviderFactories in a resource.TestStep within an acceptance test.

func RandInt

func RandInt(t *testing.T) int

func RandString

func RandString(t *testing.T, length int) string

func RemoveContainerServiceAgentRoleFromContainerEngineRobot

func RemoveContainerServiceAgentRoleFromContainerEngineRobot(t *testing.T, project *cloudresourcemanager.Project)

func SetupProjectsAndGetAccessToken

func SetupProjectsAndGetAccessToken(org, billing, pid, service string, config *transport_tpg.Config) (string, error)

func SetupTestEnvs

func SetupTestEnvs(t *testing.T, envValues map[string]string)

func SkipIfVcr

func SkipIfVcr(t *testing.T)

Some tests fail during VCR. One common case is race conditions when creating resources. If a test config adds two fine-grained resources with the same parent it is undefined which will be created first, causing VCR to fail ~50% of the time

func SleepInSecondsForTest

func SleepInSecondsForTest(t int) resource.TestCheckFunc

func TestBucketName

func TestBucketName(t *testing.T) string

func TestCheckAttributeValuesEqual

func TestCheckAttributeValuesEqual(i *string, j *string) resource.TestCheckFunc

TestCheckAttributeValuesEqual compares two string pointers, which have been used to retrieve attribute values from the test's state.

func TestExtractResourceAttr

func TestExtractResourceAttr(resourceName string, attributeName string, attributeValue *string) resource.TestCheckFunc

TestExtractResourceAttr navigates a test's state to find the specified resource (or data source) attribute and makes the value accessible via the attributeValue string pointer.

func UnsetTestProviderConfigEnvs

func UnsetTestProviderConfigEnvs(t *testing.T)

UnsetProviderConfigEnvs unsets any ENVs in the test environment that configure the provider. The testing package will restore the original values after the test

func VcrTest

func VcrTest(t *testing.T, c resource.TestCase)

VcrTest is a wrapper for resource.Test to swap out providers for VCR providers and handle VCR specific things Can be called when VCR is not enabled, and it will behave as normal

Types

type BootstrappedKMS

type BootstrappedKMS struct {
	*cloudkms.KeyRing
	*cloudkms.CryptoKey
}

func BootstrapKMSKey

func BootstrapKMSKey(t *testing.T) BootstrappedKMS

func BootstrapKMSKeyInLocation

func BootstrapKMSKeyInLocation(t *testing.T, locationID string) BootstrappedKMS

func BootstrapKMSKeyWithPurpose

func BootstrapKMSKeyWithPurpose(t *testing.T, purpose string) BootstrappedKMS

BootstrapKMSKeyWithPurpose returns a KMS key in the "global" location. See BootstrapKMSKeyWithPurposeInLocation.

func BootstrapKMSKeyWithPurposeInLocation

func BootstrapKMSKeyWithPurposeInLocation(t *testing.T, purpose, locationID string) BootstrappedKMS

* * BootstrapKMSKeyWithPurposeInLocation will return a KMS key in a * particular location with the given purpose that can be used * in tests that are testing KMS integration with other resources. * * This will either return an existing key or create one if it hasn't been created * in the project yet. The motivation is because keyrings don't get deleted and we * don't want a linear growth of disabled keyrings in a project. We also don't want * to incur the overhead of creating a new project for each test that needs to use * a KMS key. *

func BootstrapKMSKeyWithPurposeInLocationAndName

func BootstrapKMSKeyWithPurposeInLocationAndName(t *testing.T, purpose, locationID, keyShortName string) BootstrappedKMS

type VcrSource

type VcrSource struct {
	// contains filtered or unexported fields
}

VcrSource is a source for a given VCR test with the value that seeded it

Jump to

Keyboard shortcuts

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