Documentation ¶
Overview ¶
Package cmdtest contains a framework for testing cobra Commands within Go unit tests.
Index ¶
- type RunResult
- type System
- func (s *System) AddCommands(cmds ...*cobra.Command)
- func (s *System) MustRun(t TestingT, args ...string) RunResult
- func (s *System) MustRunC(t TestingT, ctx context.Context, args ...string) RunResult
- func (s *System) MustRunWithInput(t TestingT, in io.Reader, args ...string) RunResult
- func (s *System) MustRunWithInputC(t TestingT, ctx context.Context, in io.Reader, args ...string) RunResult
- func (s *System) Run(args ...string) RunResult
- func (s *System) RunC(ctx context.Context, args ...string) RunResult
- func (s *System) RunWithInput(in io.Reader, args ...string) RunResult
- func (s *System) RunWithInputC(ctx context.Context, in io.Reader, args ...string) RunResult
- type TestingT
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type RunResult ¶
RunResult is the stdout and stderr resulting from a call to a System's Run family of methods, and any error that was returned.
type System ¶
type System struct {
// contains filtered or unexported fields
}
System is a system under test.
func (*System) AddCommands ¶
AddCommands sets commands to be available to the Run family of methods on s.
func (*System) MustRunC ¶
MustRunC calls s.RunWithInput, but also calls t.FailNow if RunResult.Err is not nil.
func (*System) MustRunWithInput ¶
MustRunWithInput calls s.RunWithInput, but also calls t.FailNow if RunResult.Err is not nil.
func (*System) MustRunWithInputC ¶
func (s *System) MustRunWithInputC(t TestingT, ctx context.Context, in io.Reader, args ...string) RunResult
MustRunWithInputC calls s.RunWithInputC, but also calls t.FailNow if RunResult.Err is not nil.
func (*System) RunWithInput ¶
RunWithInput calls s.RunWithInputC with context.Background().
func (*System) RunWithInputC ¶
RunWithInputC executes a new root command with subcommands that were set in s.AddCommands(). The command's stdin is set to the in argument. RunWithInputC returns a RunResult wrapping stdout, stderr, and any returned error.