Documentation ¶
Overview ¶
Package mockenv contains facilities for unit testing commands
Index ¶
- type DevPlumbing
- func (dp DevPlumbing) Backward(url string) string
- func (dp DevPlumbing) Clone(stream stream.IOStream, remoteURI, clonePath string, extraArgs ...string) error
- func (dp DevPlumbing) Fetch(stream stream.IOStream, clonePath string, cache any) (err error)
- func (dp DevPlumbing) Forward(url string) string
- func (dp DevPlumbing) GetCanonicalRemote(clonePath string, repoObject any) (name string, urls []string, err error)
- func (dp DevPlumbing) GetRemotes(clonePath string, repoObject any) (remotes map[string][]string, err error)
- func (dp DevPlumbing) Pull(stream stream.IOStream, clonePath string, cache any) (err error)
- func (dp DevPlumbing) SetRemoteURLs(clonePath string, repoObject any, name string, urls []string) (err error)
- type MockEnv
- func (mock *MockEnv) AssertOutput(t TestingT, prefix, got string, wants ...string)
- func (mock *MockEnv) Clone(remote string, path ...string) (clonePath string)
- func (mock *MockEnv) Install(remote string, path ...string) string
- func (mock *MockEnv) Register(remotes ...string) (repo *git.Repository)
- func (mock MockEnv) Resolve(path ...string) string
- func (mock *MockEnv) Run(command ggman.Command, workdir string, stdin string, argv ...string) (code uint8, stdout, stderr string)
- type TestingT
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type DevPlumbing ¶ added in v1.15.0
type DevPlumbing struct { // Plumbing is the underlying plumbing used by this DevPlumbing. git.Plumbing // when set to true, silence standard error output for any operations. SilenceStderr bool // URLMap is the map that contains the mapping that URLs are mapped via. // Keys correspond to URLs passed to this plumbing. // Values take the form of url passed to the underlying plumbing. URLMap map[string]string }
DevPlumbing is a version of a git.Plumbing that runs all URLs via a translation mapping and can optionally silence standard error output. It otherwise wraps an underlying plumbing that is used for all operations.
It is intended for use during for testing. It should be used in git operations that would otherwise require a real remote repository.
func (DevPlumbing) Backward ¶ added in v1.15.0
func (dp DevPlumbing) Backward(url string) string
Backward maps a URL passed to the underlying plumbing into a URL to this plumbing. When the url does not exist in the mapping, calls panic().
func (DevPlumbing) Clone ¶ added in v1.15.0
func (dp DevPlumbing) Clone(stream stream.IOStream, remoteURI, clonePath string, extraArgs ...string) error
Clone translates remoteURI and calls Clone on the underlying Plumbing.
func (DevPlumbing) Forward ¶ added in v1.15.0
func (dp DevPlumbing) Forward(url string) string
Forward maps a URL passed to this plumbing into a URL to the underlying plumbing. When the url does not exist in the mapping, calls panic().
func (DevPlumbing) GetCanonicalRemote ¶ added in v1.15.0
func (dp DevPlumbing) GetCanonicalRemote(clonePath string, repoObject any) (name string, urls []string, err error)
GetCanonicalRemote calls GetCanonicalRemote() on the underlying Plumbing and translates all returned urls.
func (DevPlumbing) GetRemotes ¶ added in v1.15.0
func (dp DevPlumbing) GetRemotes(clonePath string, repoObject any) (remotes map[string][]string, err error)
GetRemotes calls GetRemotes() on the underlying Plumbing and translates the returned URLs.
func (DevPlumbing) SetRemoteURLs ¶ added in v1.15.0
func (dp DevPlumbing) SetRemoteURLs(clonePath string, repoObject any, name string, urls []string) (err error)
SetRemoteURLs translates urls and calls SetRemoteURLs() on the underlying Plumbing.
type MockEnv ¶
type MockEnv struct {
// contains filtered or unexported fields
}
MockEnv represents a new environment that can be used for testing ggman commands.
The mocked environment creates a temporary folder which can be used to hold repositories. In order to mock a certain local state, repositories can be installed into this folder using the Register() and Install() commands.
func NewMockEnv ¶
NewMockEnv creates a new MockEnv for testing ggman programs.
func (*MockEnv) AssertOutput ¶
AssertOutput asserts that the standard error or output returned by Run() is equal to one of wants. If this is not the case, calls TestingT.Errorf() with an error message relating to the last want.
For consistency across runs, strings of the form `${GGROOT a b c}` in want are resolved into an absolute path. Furthermore when `${}` is surrounded by "s, (e.g. "${GGROOT a b c}"), go quotes the string. When text is instead surrounded by “s`s, (e.g. `${GGROOT a b c}`) shell escapes the string.
Context should be additional information to be prefixed for the error message.
func (*MockEnv) Clone ¶ added in v1.13.0
Clone is like Install, but calls Register(remote) beforehand. Returns the return value of Install.
This function is untested because Register and Install are tested.
func (*MockEnv) Install ¶
Install installs the provided remote into the provided path. Returns the path the repository has been installed into. Assumes that the remote has been registered.
When the remote has not been registered, consider using Install instead.
If something goes wrong, calls panic().
func (*MockEnv) Register ¶
Register registers a new remote repository with the provided urls. All remote urls point to the same path. Returns a reference to the remote repository.
Remotes must not have been registered before, or panic() will be called.
The purpose of registering a remote is that it does not place a requirement for external services to be alive during testing. Calls to clone or fetch the provided repository will instead of talking to the remote talk to this dummy repository instead.
func (*MockEnv) Run ¶
func (mock *MockEnv) Run(command ggman.Command, workdir string, stdin string, argv ...string) (code uint8, stdout, stderr string)
Run runs the command with the provided arguments. It afterwards resets the concrete value stored in command to it's zero value.
The arguments should include the name of the command. The command is provided the given string as standard input.
Commands are not executed on the real system; instead they are executed within the sandboxed environment. In particular all interactions with remote git repositories are intercepted, see the Register() method for details.
Run returns the exit code of the provided command, along with standard output and standard error.