A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://pkg.go.dev/github.com/terramate-io/terramate@v0.14.4/test/sandbox below:

sandbox package - github.com/terramate-io/terramate/test/sandbox - Go Packages

Package sandbox provides an easy way to setup isolated terramate projects that can be used on testing, acting like sandboxes.

It helps with:

- git initialization/operations - Terraform module creation - Terramate stack creation

This section is empty.

This section is empty.

This section is empty.

type AssertTreeOption func(o *assertTreeOptions)

AssertTreeOption is the common option type for AssertTree.

WithStrictStackValidation is an option for AssertTree to validate that the list of stacks given in the layout _exactly_ matches the list of stacks in the tree, i.e. it doesn't just check that the given stacks exist, but also that there are no other stacks beyond that.

DirEntry represents a directory and can be used to create files inside the directory.

Chmod does the same as test.Chmod for the given file/dir inside this DirEntry.

CreateConfig will create a Terramate config file inside this dir entry with the given body using the default Terramate config filename.

It returns a file entry that can be used to further manipulate the created file, like replacing its contents. The file entry is optimized for always replacing the file contents, not streaming (using file as io.Writer).

If the file already exists its contents will be truncated, like os.Create behavior: https://pkg.go.dev/os#Create

CreateDir creates a directory inside the dir entry directory. The relpath must be relative to the stack directory.

CreateFile will create a file inside this dir entry with the given name and the given body. The body can be plain text or a format string identical to what is defined on Go fmt package.

It returns a file entry that can be used to further manipulate the created file, like replacing its contents. The file entry is optimized for always replacing the file contents, not streaming (using file as io.Writer).

If the file already exists its contents will be truncated, like os.Create behavior: https://pkg.go.dev/os#Create

DeleteConfig deletes the default Terramate config file.

Git returns a Git wrapper for the dir.

ListGenFiles lists all files generated by Terramate for this dir entry.

Path returns the absolute path of the directory entry.

ReadFile will read a file inside this dir entry with the given name. It will fail the test if the file doesn't exist, since it assumes an expectation on the file being there.

RelPath returns the relative path of the directory entry using the host path separator.

RemoveFile will delete a file inside this dir entry with the given name. It will succeeds if the file already doesn't exist.

type FileEntry struct {
	
}

FileEntry represents a file and can be used to manipulate the file contents. It is optimized for reading/writing all contents, not stream programming (io.Reader/io.Writer). It has limited usefulness but it is easier to work with for testing.

Chmod changes the file mod, like os.Chmod.

HostPath returns the absolute path of the file.

Path returns the absolute project path of the file.

Write writes the given text body on the file, replacing its contents. The body can be plain text or a format string identical to what is defined on Go fmt package.

It behaves like os.WriteFile: https://pkg.go.dev/os#WriteFile

Git is a git wrapper that makes testing easy by handling errors automatically, failing the caller test.

NewGit creates a new git wrapper using sandbox defaults.

NewGitWithConfig creates a new git wrapper with the provided GitConfig.

Add will add files to the commit list

AddSubmodule adds name as a submodule for the provided url.

BareRepoAbsPath returns the path for the bare remote repository of this repository.

BaseDir the repository base dir

Checkout will checkout a pre-existing revision

CheckoutNew will checkout a new revision (creating it on the process)

Clone will clone a repository into the given dir.

Commit will commit previously added files

CommitAll will add all changed files and commit all of them. It requires files to be committed otherwise it fails.

CurrentBranch returns the short branch name that HEAD points to.

DeleteBranch deletes the ref branch.

Init will initialize the local git repo with a default remote. After calling Init(), the methods Push() and Pull() pushes and pulls changes from/to the configured default remote.

func (git Git) InitLocalRepo()

InitLocalRepo will do the git initialization of a local repository, not providing a remote configuration.

Merge will merge the current branch with the given branch. Fails the caller test if an error is found.

Pull pulls changes from default remote into branch

Push pushes changes from branch onto default remote and same remote branch name.

func (git Git) PushOn(remote, remoteBranch, localBranch string)

PushOn pushes changes from localBranch onto the given remote and remoteBranch.

RemoteAdd adds a new remote on the repo

RevParse parses the reference name and returns the reference hash.

func (git Git) SetRemoteURL(remote, url string)

SetRemoteURL sets the URL of the remote.

func (git Git) SetupRemote(remoteName, remoteBranch, localBranch string)

SetupRemote creates a bare remote repository and setup the local repo with it using remoteName and remoteBranch.

Unwrap returns the wrapped git instance.

type GitConfig struct {
	LocalBranchName         string
	DefaultRemoteName       string
	DefaultRemoteBranchName string
	
}

GitConfig configures the sandbox's git repository.

type S struct {
	Env []string
	
}

S is a full sandbox with its own base dir that is an initialized git repo for test purposes.

New creates a new complete test sandbox. The git repository is set up with sane defaults.

It is a programming error to use a test env created with a testing.TB other than the one of the test using the test env, for a new test/sub-test always create a new test env for it.

NewWithGitConfig creates a new sandbox using the cfg configuration for the git repository.

NoGit creates a new test sandbox with no git repository.

It is a programming error to use a test env created with a testing.TB other than the one of the test using the test env, for a new test/sub-test always create a new test env for it.

AssertTree compares the current tree against the given layout specification. The specification works similar to BuildTree.

The following directives are supported:

"s:<stackpath>" or "stack:..." Assert that stackpath is a stack.

"d:<dirpath>" or "dir:..." Assert that dirpath is an existing directory.

"f:<filepath>[:<content>]" or "file:..." Assert that filepath is an existing file, optionally having the given content.

func (s S) BuildTree(layout []string)

BuildTree builds a tree layout based on the layout specification. Each string in the slice represents a filesystem operation, and each operation has the format below:

<kind>:<param1>[:param2]

Where kind is one of the below:

"d" or "dir" for directory creation.
"g" or "git" for local git directory creation.
"s" or "stack" for initialized stacks.
"f" or "file" for file creation.
"l" or "link" for symbolic link creation.
"copy" for copying directories or files.
"run" for executing a command inside directory.

And [:param2] is optional and it depends on the kind.

For the operations "f" and "s" [:param2] is defined as:

For "f" it is the content of the file to be created.
For "s" it is a key value pair of the form:
  <attr1>=<val1>[;<attr2>=<val2>]

Where attrN is a string attribute of the terramate block of the stack. Example:

s:name-of-the-stack:id=stack-id;after=["other-stack"]

For the operation "l" the [:param2] is the link name, while <param1> is the target of the symbolic link:

l:<target>:<link name>

So this:

l:dir/file:dir/link

Is equivalent to:

ln -s dir/file dir/link

For "copy" the [:param1] is the source directory and [:param2] is the target directory.

For "run" the [:param1] is the working directory and [:param2] is the command to be executed.

This is an internal mini-lang used to simplify testcases, so it expects well formed layout specification.

Config returns the root configuration for the sandbox. It memoizes the parsing output, then multiple calls will parse the configuration once.

CreateModule will create a module dir with the given relative path, returning a directory entry that can be used to create files inside the module dir.

CreateStack will create a stack dir with the given relative path and initializes the stack, returning a stack entry that can be used to create files inside the stack dir.

If the path is absolute, it will be considered in relation to the sandbox root dir.

DirEntry gets the dir entry for relpath. The dir must exist and must be a relative path to the sandbox root dir. The relpath must be a forward-slashed path.

Generate generates code for all stacks on the sandbox

GenerateWith generates code for all stacks inside the provided path.

Git returns a git wrapper that is useful to run git commands safely inside the test env repo.

IsGit tells if the sandbox is a git repository.

LoadStack load the stack given its relative path.

LoadStackGlobals loads globals for specific stack on the sandbox. Fails the caller test if an error is found.

LoadStacks load all stacks from sandbox rootdir.

ReloadConfig reloads the sandbox configuration.

RootDir returns the root directory of the test env. All dirs/files created through the test env will be included inside this dir.

It is a programming error to delete this dir, it will be automatically removed when the test finishes.

RootEntry returns a DirEntry for the root directory of the test env.

StackEntry gets the stack entry of the stack identified by relpath. The stack must exist (previously created).

StackEntry represents a directory that's also a stack. It extends a DirEntry with stack specific functionality.

DeleteStackConfig deletes the default stack definition file.

Load loads the terramate stack instance for this stack dir entry.

ModSource returns the relative import path for the module with the given module dir entry. The path is relative to stack dir itself (hence suitable to be a module source path).

Path returns the absolute path of the stack.

ReadFile will read the given file that must be located inside the stack.

RelPath returns the relative path of the stack. It is relative to the base dir of the test environment that created this stack.

WriteConfig will create a terramate configuration file on the stack or replace the current config if there is one.


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4