helpers

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jan 30, 2025 License: MIT Imports: 40 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

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

func CleanupTerragruntFolder

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

func CopyAndFillMapPlaceholders

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

func CopyEnvironment

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

func CopyTerragruntConfigAndFillPlaceholders

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

func CreateEmptyStateFile

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

func CreateTmpTerragruntConfig

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

func CreateTmpTerragruntConfigContent

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

func CreateTmpTerragruntConfigWithParentAndChild

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

func DeleteS3Bucket

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

DeleteS3Bucket deletes the specified S3 bucket to clean up after a test, and fails the test if there was an error.

func DeleteS3BucketE

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

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

func ExpectedWrongCommandErr

func ExpectedWrongCommandErr(command string) error

ExpectedWrongCommandErr - return expected error message for wrong command

func FileIsInFolder

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

func FindFilesWithExtension

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

func GetPathRelativeTo

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

func GetPathsRelativeTo

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

func IsTerraform

func IsTerraform() bool

func LogBufferContentsLineByLine

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

func RemoveFile

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

func RemoveFolder

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

func RunNetworkMirrorServer

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

func RunTerragrunt

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

func RunTerragruntCommand

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

func RunTerragruntCommandWithContext

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

func RunTerragruntCommandWithOutput

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

func RunTerragruntCommandWithOutputWithContext

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

func RunTerragruntRedirectOutput

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

func RunTerragruntValidateInputs

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

func RunTerragruntVersionCommand

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

func RunValidateAllWithIncludeAndGetIncludedModules

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

func TestRunAllPlan

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

func UniqueID

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

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

func WrappedBinary

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

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

func (*FakeProvider) CreateMirror

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

type TerraformOutput

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

Jump to

Keyboard shortcuts

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