shelltest

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Apr 25, 2021 License: GPL-3.0 Imports: 7 Imported by: 0

Documentation

Overview

Package shelltest provides utilities for mocking the login shell.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Command

type Command struct {
	ReturnCode int
	Stdout     string
	Stderr     string
}

Command represents the result of some executed command.

type ErrCommandOverflow added in v0.0.10

type ErrCommandOverflow struct {
	Index   int
	Len     int
	Command string
}

ErrCommandOverflow happens when the command that is trying to be run would result in a buffer overflow in the Shell mock.

func (ErrCommandOverflow) Error added in v0.0.10

func (e ErrCommandOverflow) Error() string

type Shell

type Shell struct {
	T                 *testing.T
	Context           *context.Context
	SupportedPrograms map[string]bool
	Commands          []Command
	// contains filtered or unexported fields
}

Shell is a type that conforms to shell.Shell.

func (*Shell) CurrentDirectory

func (sh *Shell) CurrentDirectory() string

CurrentDirectory returns the current directory.

func (*Shell) Exec

func (sh *Shell) Exec(cmd *exec.Cmd) (*shell.CompletedProcess, error)

Exec executes the command.

func (*Shell) Exists

func (sh *Shell) Exists(program string) bool

Exists returns whether the given program exists.

This implementation of the method returns true if the SupportedPrograms field is empty, otherwise it checks the value of the key in that map. Use SupportedPrograms to mock the existence of a program in the PATH.

func (*Shell) NewCommand

func (sh *Shell) NewCommand(name string, arg ...string) *exec.Cmd

NewCommand takes a program and arguments and constructs a new exec.Cmd instance.

Jump to

Keyboard shortcuts

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