utils

package
v0.0.0-...-fd3f69f Latest Latest
Warning

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

Go to latest
Published: Apr 18, 2024 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultTimeout = 10 * time.Second
)

Variables

This section is empty.

Functions

func UserConfigEnv

func UserConfigEnv(dir string) map[string]string

UserConfigEnv creates environment variable for changing user config dir (By setting $XDG_CONFIG_HOME).

Types

type ExecOpts

type ExecOpts struct {
	// contains filtered or unexported fields
}

ExecOpts is an option used to execute a command.

func Binary

func Binary(binPath string) *ExecOpts

Binary returns default execution option for customized binary.

func (*ExecOpts) Clear

func (opts *ExecOpts) Clear()

Clear clears the ExecOpts to get ready for the next execution.

func (*ExecOpts) Exec

func (opts *ExecOpts) Exec(args ...string) *Matcher

Exec run the execution based on opts.

func (*ExecOpts) ExpectBlocking

func (opts *ExecOpts) ExpectBlocking() *ExecOpts

ExpectBlocking consistently check if the execution is blocked.

func (*ExecOpts) ExpectFailure

func (opts *ExecOpts) ExpectFailure() *ExecOpts

ExpectFailure sets failure exit code checking for the execution.

func (*ExecOpts) WithDescription

func (opts *ExecOpts) WithDescription(text string) *ExecOpts

WithDescription sets description text for the execution.

func (*ExecOpts) WithEnv

func (opts *ExecOpts) WithEnv(env map[string]string) *ExecOpts

WithEnv update the environment variables.

func (*ExecOpts) WithInput

func (opts *ExecOpts) WithInput(r io.Reader) *ExecOpts

WithInput redirects stdin to r for the execution.

func (*ExecOpts) WithTimeOut

func (opts *ExecOpts) WithTimeOut(timeout time.Duration) *ExecOpts

WithTimeOut sets timeout for the execution.

func (*ExecOpts) WithWorkDir

func (opts *ExecOpts) WithWorkDir(path string) *ExecOpts

WithWorkDir sets working directory for the execution.

type HostOption

type HostOption func(vhost *VirtualHost) error

HostOption is a function to set the host configuration.

type Matcher

type Matcher struct {
	Session *gexec.Session
	// contains filtered or unexported fields
}

Matcher contains the execution result for matching.

func NewMatcher

func NewMatcher(session *gexec.Session) *Matcher

NewMatcher returns a new Matcher.

func (*Matcher) MatchContent

func (m *Matcher) MatchContent(content string) *Matcher

MatchContent matches the content with the stdout.

func (*Matcher) MatchErrContent

func (m *Matcher) MatchErrContent(content string) *Matcher

MatchErrContent matches the content with stderr.

func (*Matcher) MatchErrKeyWords

func (m *Matcher) MatchErrKeyWords(keywords ...string) *Matcher

MatchErrKeyWords matches given keywords with the stderr.

func (*Matcher) MatchKeyWords

func (m *Matcher) MatchKeyWords(keywords ...string) *Matcher

MatchKeyWords matches given keywords with the stdout.

func (*Matcher) NoMatchErrKeyWords

func (m *Matcher) NoMatchErrKeyWords(keywords ...string) *Matcher

NoMatchErrKeyWords guarantees that the given keywords do not match with the stderr.

type VirtualHost

type VirtualHost struct {
	Executor *ExecOpts
	// contains filtered or unexported fields
}

VirtualHost is a virtualized host machine isolated by environment variable.

func NewVirtualHost

func NewVirtualHost(binPath string, options ...HostOption) (*VirtualHost, error)

NewVirtualHost creates a temporary user-level directory and updates the "XDG_CONFIG_HOME" environment variable for Executor of the VirtualHost.

func (*VirtualHost) AbsolutePath

func (h *VirtualHost) AbsolutePath(elem ...string) string

AbsolutePath returns the absolute path for the given path elements that are relative to the user directory.

func (*VirtualHost) SetOption

func (h *VirtualHost) SetOption(options ...HostOption)

SetOption sets the options for the host.

func (*VirtualHost) UpdateEnv

func (h *VirtualHost) UpdateEnv(env map[string]string)

UpdateEnv updates the environment variables for the VirtualHost.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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