Documentation ¶
Overview ¶
Package test provides testing routines reused throughout terramate code base.
Index ¶
- Constants
- func AppendFile(t testing.TB, dir string, filename string, content string)
- func AssertChmod(t testing.TB, fname string, mode fs.FileMode)
- func AssertConfigEquals(t *testing.T, got, want []config.Assert)
- func AssertDiff(t *testing.T, got, want interface{}, msg ...interface{})
- func AssertEqualPaths(t *testing.T, got, want project.Path, fmtargs ...any)
- func AssertEqualPos(t *testing.T, got, want info.Pos, fmtargs ...any)
- func AssertEqualRanges(t *testing.T, got, want info.Range, fmtargs ...any)
- func AssertEqualSets[T comparable](t *testing.T, got, want []T)
- func AssertFileContentEquals(t *testing.T, fname string, want string)
- func AssertFileEquals(t *testing.T, filepath1, filepath2 string)
- func AssertGenCodeEquals(t *testing.T, got string, want string)
- func AssertStackImports(t *testing.T, rootdir string, stackHostPath string, want []string)
- func AssertStacks(t testing.TB, got, want config.Stack)
- func AssertTerramateConfig(t *testing.T, got, want hcl.Config)
- func AssertTreeEquals(t *testing.T, dir1, dir2 string)
- func CanonPath(t testing.TB, path string) string
- func Chmod(fname string, mode fs.FileMode) error
- func DoesNotExist(t testing.TB, dir, fname string)
- func EmptyRepo(t testing.TB, bare bool) string
- func FixupRangeOnAsserts(dir string, asserts []config.Assert)
- func Getwd(t testing.TB) string
- func IsDir(t testing.TB, dir, fname string)
- func IsFile(t testing.TB, dir, fname string)
- func LookPath(t *testing.T, file string) string
- func Mkdir(t testing.TB, base string, name string) string
- func MkdirAll(t testing.TB, path string)
- func MkdirAll2(t testing.TB, path string, perm fs.FileMode)
- func NewExpr(t *testing.T, expr string) hhcl.Expression
- func NewGitWrapper(t testing.TB, wd string, env []string) *git.Git
- func NewRepo(t testing.TB) string
- func NonExistingDir(t testing.TB) string
- func ParseSource(t *testing.T, source string) tf.Source
- func ParseTerramateConfig(t *testing.T, dir string) hcl.Config
- func PrependToPath(env []string, dir string) ([]string, bool)
- func ReadDir(t testing.TB, dir string) []os.DirEntry
- func ReadFile(t testing.TB, dir, fname string) []byte
- func RelPath(t testing.TB, basepath, targetpath string) string
- func RemoveAll(t testing.TB, path string)
- func RemoveFile(t testing.TB, dir, fname string)
- func Symlink(t testing.TB, oldname, newname string)
- func TempDir(t testing.TB) string
- func WriteFile(t testing.TB, dir string, filename string, content string) string
- func WriteRootConfig(t testing.TB, rootdir string)
Constants ¶
const ( // Username for the test commits. Username = "terramate tests" // Email for the test commits. Email = "terramate@mineiros.io" // DefBranch is the default repository branch. DefBranch = "main" )
Variables ¶
This section is empty.
Functions ¶
func AppendFile ¶
AppendFile appends content to a filename inside dir directory. If file exists, appends on the end of it by adding a newline, if file doesn't exists it will be created.
func AssertChmod ¶ added in v0.4.3
AssertChmod is a portable version of the os.AssertChmod.
func AssertConfigEquals ¶
AssertConfigEquals asserts that two config.Assert are equal.
func AssertDiff ¶
AssertDiff will compare the two values and fail if they are not the same providing a comprehensive textual diff of the differences between them. If provided msg must be a string + any formatting parameters. The msg will be added if the assertion fails.
func AssertEqualPaths ¶
AssertEqualPaths checks if two paths are equal.
func AssertEqualPos ¶
AssertEqualPos checks if two ast.Pos are equal.
func AssertEqualRanges ¶
AssertEqualRanges checks if two ranges are equal. If the wanted range is zero value of the type no check will be performed since this communicates that the caller is not interested on validating the range.
func AssertEqualSets ¶
func AssertEqualSets[T comparable](t *testing.T, got, want []T)
AssertEqualSets checks if two sets contains the same elements independent of order (handles slices as sets).
func AssertFileContentEquals ¶
AssertFileContentEquals asserts that file fname has the content of want. It assumes the file content is a unicode string.
func AssertFileEquals ¶
AssertFileEquals asserts that the two given files are the same. It assumes they are text files and shows a diff in case they are not the same.
func AssertGenCodeEquals ¶
AssertGenCodeEquals checks if got gen code equals want. Since got is generated by Terramate it will be stripped of its Terramate header (if present) before comparing with want.
func AssertStackImports ¶
AssertStackImports checks that the given stack has all the wanted import definitions. The wanted imports is a slice of the sources that are imported on each block.
func AssertStacks ¶ added in v0.4.4
AssertStacks asserts that s1 and s2 are equal.
func AssertTerramateConfig ¶
AssertTerramateConfig checks if two given Terramate configs are equal.
func AssertTreeEquals ¶
AssertTreeEquals asserts that the two given directories are the same. This means they must have the same files and also same subdirs with same files inside recursively.
func CanonPath ¶
CanonPath returns a canonical absolute path for the given path. Fails the test if any error is found.
func DoesNotExist ¶ added in v0.4.3
DoesNotExist calls os.Stat and asserts that the entry does not exist
func EmptyRepo ¶
EmptyRepo creates and initializes a git repository and checks for errors. If bare is provided, the repository is for revisions (ie: for pushs)
func FixupRangeOnAsserts ¶
FixupRangeOnAsserts fixes the range on all the given asserts. It assumes the asserts where created with relative paths and will join the relative path with the given dir to provide a final absolute path.
func LookPath ¶
LookPath is identical to exec.LookPath except it will fail the test if the lookup fails
func NewExpr ¶
func NewExpr(t *testing.T, expr string) hhcl.Expression
NewExpr parses the given string and returns a hcl.Expression.
func NewGitWrapper ¶
NewGitWrapper tests the creation of a git wrapper and returns it if success. The env is the list of environment variables to be passed to git but if nil is provided then the complete os.Environ() is used.
func NewRepo ¶
NewRepo creates and initializes a repository for terramate use cases. It initializes two repositories, one for working and other bare for the "remote". It sets up the working repository with a "origin" remote pointing to the local "bare" repository and push a initial main commit onto origin/main. The working git repository is returned and the other is automatically cleaned up when the test function finishes.
func NonExistingDir ¶
NonExistingDir returns a non-existing directory.
func ParseSource ¶
ParseSource calls tf.ParseSource failing the test if it fails.
func ParseTerramateConfig ¶
ParseTerramateConfig parses the Terramate configuration found on the given dir, returning the parsed configuration.
func PrependToPath ¶ added in v0.4.3
PrependToPath prepend a directory to the OS PATH variable in a portable way. It returns the new env slice and a boolean telling if the env was updated or not.
func RemoveFile ¶
RemoveFile removes the file fname from dir directory. If the files doesn't exists, it succeeds.
func Symlink ¶
Symlink calls os.Symlink failing the test if there is an error.
func WriteFile ¶
WriteFile writes content to a filename inside dir directory. If dir is empty string then the file is created inside a temporary directory.
func WriteRootConfig ¶
WriteRootConfig writes a basic terramate root config.
Types ¶
This section is empty.
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
Package cloud provides testing helpers for the TMC cloud.
|
Package cloud provides testing helpers for the TMC cloud. |
Package errors provides useful assert functions for handling errors on tests
|
Package errors provides useful assert functions for handling errors on tests |
Package hclutils provides test utils related to hcl.
|
Package hclutils provides test utils related to hcl. |
info
Package info provides functions useful to create types like [info.Range]
|
Package info provides functions useful to create types like [info.Range] |
Package hclwrite aims to provide some facilities making it easier/safer to generate HCL code for testing purposes.
|
Package hclwrite aims to provide some facilities making it easier/safer to generate HCL code for testing purposes. |
hclutils
Package hclutils provides useful functions to build HCL documents.
|
Package hclutils provides useful functions to build HCL documents. |
Package ls provides test utilities used when testing the Terramate Language Server.
|
Package ls provides test utilities used when testing the Terramate Language Server. |
Package sandbox provides an easy way to setup isolated terramate projects that can be used on testing, acting like sandboxes.
|
Package sandbox provides an easy way to setup isolated terramate projects that can be used on testing, acting like sandboxes. |