utils

package
v0.0.0-...-ae6de38 Latest Latest
Warning

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

Go to latest
Published: Oct 6, 2023 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var AzureRmAndRequiredProviders setuptest.PrepFunc = func(resp setuptest.Response) error {
	if err := createAzureRmProvidersFile(resp.TmpDir); err != nil {
		return err
	}
	return generateRequiredProvidersFile(newRequiredProvidersData(), filepath.Clean(resp.TmpDir+"/terraform.tf"))
}

AzureRmAndRequiredProviders is a setuptest.SetupTestPrepFunc that will create

- a required providers file in the given temporary directory (with version constraints from env vars) - a azurerm providers file in the given temporary directory

View Source
var RequiredProviders setuptest.PrepFunc = func(resp setuptest.Response) error {
	return generateRequiredProvidersFile(newRequiredProvidersData(), filepath.Clean(resp.TmpDir+"/terraform.tf"))
}

RequiredProviders is a setuptest.SetupTestPrepFunc that will create a required providers file in the given temporary directory.

Functions

func GetLogger

func GetLogger() *logger.Logger

GetLogger returns a logger that can be used for testing. The default logger will discard the Terraform output. Set TERRATEST_LOGGER to a non empty value to enable verbose logging.

func GetTestDir

func GetTestDir(t *testing.T) string

GetTestDir returns the directory of the test file.

func PreCheckDeployTests

func PreCheckDeployTests(t *testing.T)

PreCheckDeployTests ensures the correct environment variables are set for the deployment tests to run.

func RandomHex

func RandomHex(n int) (string, error)

RandomHex generates a random hex string of the given byte length. Uses crypto/rand for generating the random bytes not math/rand as we kept getting the same results from the math/rand generator.

func SanitiseErrorMessage

func SanitiseErrorMessage(err error) string

SanitiseErrorMessage replaces the newline characters in an error.Error() output with a single space to allow us to check for the entire error message. We need to do this because Terraform adds newline characters depending on the width of the console window. TODO: Test on Windows if we get \r\n instead of just \n.

Types

type RequiredProvidersData

type RequiredProvidersData struct {
	AzAPIVersion   string
	AzureRMVersion string
}

RequiredProvidersData is the data struct for the Terraform required providers block. It should ordinarily be generated using utils.NewRequiredProvidersData().

Jump to

Keyboard shortcuts

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