helpers

package
v0.77.21 Latest Latest
Warning

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

Go to latest
Published: Apr 21, 2025 License: MIT Imports: 42 Imported by: 0

Documentation

Overview

Package helpers provides helper functions for tests.

Index

Constants

View Source
const (
	TerraformFolder = ".terraform"

	TerraformState = "terraform.tfstate"

	TerraformRemoteStateS3Region = "us-west-2"

	TerraformStateBackup = "terraform.tfstate.backup"
	TerragruntCache      = ".terragrunt-cache"

	TerraformBinary = "terraform"
	TofuBinary      = "tofu"

	TerragruntDebugFile = "terragrunt-debug.tfvars.json"

	// Repeated right now, but it might not be later.
	TestFixtureOutDir = "fixtures/out-dir"
)

Variables

View Source
var RootFolder = "/"

Functions

func CleanupTerraformFolder added in v0.68.13

func CleanupTerraformFolder(t *testing.T, templatesPath string)

func CleanupTerragruntFolder added in v0.68.13

func CleanupTerragruntFolder(t *testing.T, templatesPath string)

func CopyAndFillMapPlaceholders added in v0.68.13

func CopyAndFillMapPlaceholders(t *testing.T, srcPath string, destPath string, placeholders map[string]string)

func CopyEnvironment added in v0.68.13

func CopyEnvironment(t *testing.T, environmentPath string, includeInCopy ...string) string

func CopyTerragruntConfigAndFillPlaceholders added in v0.68.13

func CopyTerragruntConfigAndFillPlaceholders(t *testing.T, configSrcPath string, configDestPath string, s3BucketName string, lockTableName string, region string)

func CreateDynamoDBClientForTest added in v0.77.0

func CreateDynamoDBClientForTest(t *testing.T, awsRegion, awsProfile, iamRoleArn string) *dynamodb.DynamoDB

CreateDynamoDBClientForTest creates a DynamoDB client we can use at test time. If there are any errors creating the client, fail the test.

func CreateEmptyStateFile added in v0.68.13

func CreateEmptyStateFile(t *testing.T, testPath string)

func CreateGitRepo added in v0.73.3

func CreateGitRepo(t *testing.T, dir string)

func CreateS3ClientForTest added in v0.77.0

func CreateS3ClientForTest(t *testing.T, awsRegion string) *s3.S3

CreateS3ClientForTest creates a S3 client we can use at test time. If there are any errors creating the client, fail the test.

func CreateTmpTerragruntConfig added in v0.68.13

func CreateTmpTerragruntConfig(t *testing.T, templatesPath string, s3BucketName string, lockTableName string, configFileName string) string

func CreateTmpTerragruntConfigContent added in v0.68.13

func CreateTmpTerragruntConfigContent(t *testing.T, contents string, configFileName string) string

func CreateTmpTerragruntConfigWithParentAndChild added in v0.68.13

func CreateTmpTerragruntConfigWithParentAndChild(t *testing.T, parentPath string, childRelPath string, s3BucketName string, parentConfigFileName string, childConfigFileName string) string

func DeleteS3Bucket added in v0.68.13

func DeleteS3Bucket(t *testing.T, awsRegion string, bucketName string, opts ...options.TerragruntOptionsFunc) error

DeleteS3Bucket deletes the specified S3 bucket potentially with error to clean up after a test.

func ExpectedWrongCommandErr added in v0.68.13

func ExpectedWrongCommandErr(command string) error

ExpectedWrongCommandErr - return expected error message for wrong command

func FileIsInFolder added in v0.68.13

func FileIsInFolder(t *testing.T, name string, path string) bool

func FindFilesWithExtension added in v0.68.13

func FindFilesWithExtension(dir string, ext string) ([]string, error)

func GetPathRelativeTo added in v0.68.13

func GetPathRelativeTo(t *testing.T, path string, basePath string) string

func GetPathsRelativeTo added in v0.68.13

func GetPathsRelativeTo(t *testing.T, basePath string, paths []string) []string

func HCLFilesInDir added in v0.77.0

func HCLFilesInDir(t *testing.T, dir string) []string

HCLFilesInDir returns a list of all HCL files in a directory.

func IsTerraform added in v0.68.13

func IsTerraform() bool

IsTerraform checks if the wrapped binary currently in use is the Terraform binary.

func IsTerraform110OrHigher added in v0.74.0

func IsTerraform110OrHigher() bool

IsTerraform110OrHigher checks if the installed Terraform binary is version 1.10.0 or higher.

func IsTerragruntProviderCacheEnabled added in v0.73.0

func IsTerragruntProviderCacheEnabled(t *testing.T) bool

func LogBufferContentsLineByLine added in v0.68.13

func LogBufferContentsLineByLine(t *testing.T, out bytes.Buffer, label string)

func RemoveFile added in v0.68.13

func RemoveFile(t *testing.T, path string)

func RemoveFolder added in v0.68.13

func RemoveFolder(t *testing.T, path string)

func RunNetworkMirrorServer added in v0.68.13

func RunNetworkMirrorServer(t *testing.T, ctx context.Context, urlPrefix, providerDir, token string) *url.URL

func RunTerragrunt added in v0.68.13

func RunTerragrunt(t *testing.T, command string)

func RunTerragruntCommand added in v0.68.13

func RunTerragruntCommand(t *testing.T, command string, writer io.Writer, errwriter io.Writer) error

func RunTerragruntCommandWithContext added in v0.69.1

func RunTerragruntCommandWithContext(t *testing.T, ctx context.Context, command string, writer io.Writer, errwriter io.Writer) error

func RunTerragruntCommandWithOutput added in v0.68.13

func RunTerragruntCommandWithOutput(t *testing.T, command string) (string, string, error)

func RunTerragruntCommandWithOutputWithContext added in v0.69.1

func RunTerragruntCommandWithOutputWithContext(t *testing.T, ctx context.Context, command string) (string, string, error)

func RunTerragruntRedirectOutput added in v0.68.13

func RunTerragruntRedirectOutput(t *testing.T, command string, writer io.Writer, errwriter io.Writer)

func RunTerragruntValidateInputs added in v0.68.13

func RunTerragruntValidateInputs(t *testing.T, moduleDir string, extraArgs []string, isSuccessTest bool)

func RunTerragruntVersionCommand added in v0.68.13

func RunTerragruntVersionCommand(t *testing.T, ver string, command string, writer io.Writer, errwriter io.Writer) error

func RunValidateAllWithIncludeAndGetIncludedModules added in v0.68.13

func RunValidateAllWithIncludeAndGetIncludedModules(t *testing.T, rootModulePath string, includeModulePaths []string, strictInclude bool) []string

func TestRunAllPlan added in v0.68.13

func TestRunAllPlan(t *testing.T, args string) (string, string, string, error)

func UniqueID added in v0.68.13

func UniqueID() string

UniqueID returns a unique (ish) id we can attach to resources and tfstate files so they don't conflict with each other Uses base 62 to generate a 6 character string that's unlikely to collide with the handful of tests we run in parallel. Based on code here: http://stackoverflow.com/a/9543797/483528

func ValidateOutput added in v0.68.13

func ValidateOutput(t *testing.T, outputs map[string]TerraformOutput, key string, value any)

func WrappedBinary added in v0.68.13

func WrappedBinary() string

WrappedBinary - return which binary will be wrapped by Terragrunt, useful in CICD to run same tests against tofu and terraform

Types

type FakeProvider added in v0.68.13

type FakeProvider struct {
	RegistryName string
	Namespace    string
	Name         string
	Version      string
	PlatformOS   string
	PlatformArch string
}

func (*FakeProvider) CreateMirror added in v0.68.13

func (provider *FakeProvider) CreateMirror(t *testing.T, rootDir string)

type TerraformOutput added in v0.68.13

type TerraformOutput struct {
	Type      any  `json:"Type"`
	Value     any  `json:"Value"`
	Sensitive bool `json:"Sensitive"`
}

Jump to

Keyboard shortcuts

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