Documentation
¶
Index ¶
- func WithApp(t *testing.T, action WithAppAction, options ...WithAppOptions)
- type WithAppAction
- type WithAppActionContext
- func (ctx *WithAppActionContext) Execute() bool
- func (ctx *WithAppActionContext) ExecuteAndExpectHelp() bool
- func (ctx *WithAppActionContext) ExpectRegex(s string, r *regexp.Regexp, errorMessage string) *WithAppActionContext
- func (ctx *WithAppActionContext) ExpectTrue(condition bool, errorMessage string) *WithAppActionContext
- func (ctx *WithAppActionContext) ExpectValue(actual interface{}, expected interface{}, errorMessage string) *WithAppActionContext
- func (ctx *WithAppActionContext) OpenTempFile() (*os.File, error)
- func (ctx *WithAppActionContext) SetArgs(args ...string) *WithAppActionContext
- func (ctx *WithAppActionContext) WithStdin(action WithAppAction, p []byte) error
- type WithAppOptions
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func WithApp ¶
func WithApp(t *testing.T, action WithAppAction, options ...WithAppOptions)
WithApp() - runs a test action for an app session
Types ¶
type WithAppAction ¶
type WithAppAction = func(ctx *WithAppActionContext) error
WithAppAction is an action for `WithApp` function
type WithAppActionContext ¶
type WithAppActionContext struct { App *types.AppContext // the underlying application context Output *bytes.Buffer // is the default output for commands RootCommand *cobra.Command // the root command T *testing.T // the testing context }
WithAppActionContext is a context for `WithAppAction`
func (*WithAppActionContext) Execute ¶
func (ctx *WithAppActionContext) Execute() bool
ctx.Execute() - executes the root command, logs an error on fail and a `false`
func (*WithAppActionContext) ExecuteAndExpectHelp ¶
func (ctx *WithAppActionContext) ExecuteAndExpectHelp() bool
ctx.ExecuteAndExpectHelp() - executes command and expects help function being executed
func (*WithAppActionContext) ExpectRegex ¶
func (ctx *WithAppActionContext) ExpectRegex(s string, r *regexp.Regexp, errorMessage string) *WithAppActionContext
ctx.ExpectRegex() - checks string against a regular expression and logs error on fail
func (*WithAppActionContext) ExpectTrue ¶
func (ctx *WithAppActionContext) ExpectTrue(condition bool, errorMessage string) *WithAppActionContext
ctx.ExpectTrue() - checks if condition is true and logs error on fail
func (*WithAppActionContext) ExpectValue ¶
func (ctx *WithAppActionContext) ExpectValue(actual interface{}, expected interface{}, errorMessage string) *WithAppActionContext
ctx.ExpectValue() - checks if an actual value is the same as an expected one and logs error on fail
func (*WithAppActionContext) OpenTempFile ¶ added in v0.43.1
func (ctx *WithAppActionContext) OpenTempFile() (*os.File, error)
ctx.OpenTempFile() - opens a new temp file
func (*WithAppActionContext) SetArgs ¶
func (ctx *WithAppActionContext) SetArgs(args ...string) *WithAppActionContext
ctx.SetArgs() - sets the arguments for root command
func (*WithAppActionContext) WithStdin ¶ added in v0.43.1
func (ctx *WithAppActionContext) WithStdin(action WithAppAction, p []byte) error
ctx.WithStdin() - prepares the context so it is using a temporary file as STDIN
type WithAppOptions ¶ added in v0.43.3
type WithAppOptions struct { PostRun func(err error, ctx *WithAppActionContext) error // an optional callback that is executed AFTER the action has been executed PreRun func(ctx *WithAppActionContext) error // an optional callback that is executed BEFORE the action is executed }
WithAppOptions stores additional options for `WithApp` function