Documentation
¶
Overview ¶
Package framework provides a tanzu cli test framework
Index ¶
- Constants
- Variables
- func ContainsAnyString(stdOut *bytes.Buffer, contains []string) error
- func ContainsString(stdOut *bytes.Buffer, contains string) error
- func Exec(command string) (stdOut, stdErr *bytes.Buffer, err error)
- func ExecContainsAnyString(command string, contains []string) error
- func ExecContainsErrorString(command, contains string) error
- func ExecContainsString(command, contains string) error
- func ExecNotContainsStdErrorString(command, contains string) error
- func FlagSet() *pflag.FlagSet
- func GenerateName() string
- func NewTestFor(pluginName string) *plugin.PluginDescriptor
- func NotContainsString(stdOut *bytes.Buffer, contains string) error
- type CleanupFunc
- type Main
- func (m *Main) AddTest(t *Test)
- func (m *Main) BuildReport()
- func (m *Main) Finish()
- func (m *Main) NewTest(name, command string, run func(t *Test) error) *Test
- func (m *Main) PrintFailure()
- func (m *Main) PrintReport(format string) error
- func (m *Main) PrintStart()
- func (m *Main) PrintSuccess()
- func (m *Main) ReportError(cmd string, err error)
- func (m *Main) ReportResult(res *Result)
- func (m *Main) ReportSuccess(cmd string)
- func (m *Main) ReportTestResult(t *Test)
- func (m *Main) RunTest(name, command string, run func(t *Test) error) error
- type Report
- type Result
- type Test
- func (t *Test) Exec() (err error)
- func (t *Test) ExecContainsAnyString(contains ...string) error
- func (t *Test) ExecContainsErrorString(contains string) error
- func (t *Test) ExecContainsString(contains string) error
- func (t *Test) ExecNotContainsStdErrorString(contains string) error
- func (t *Test) PrintSuccess()
- func (t *Test) Run() error
- func (t *Test) StdErr() *bytes.Buffer
- func (t *Test) StdOut() *bytes.Buffer
- func (t *Test) Wrap(f func(t *Test) error) error
Constants ¶
const (
CLIName = "tanzu"
)
const NamePrefix = "cli-test"
NamePrefix is the prefix used in generated names.
Variables ¶
var NoCleanupFunc = func() error { return nil }
NoCleanupFunc is cleanup function that just returns nil.
Functions ¶
func ContainsAnyString ¶
ContainsAnyString checks that the given buffer contains any of the given set of strings.
func ContainsString ¶
ContainsString checks that the given buffer contains the string.
func ExecContainsAnyString ¶
ExecContainsAnyString checks that the given command output contains any of the given set of strings.
func ExecContainsErrorString ¶
ExecContainsErrorString checks that the given command stdErr output contains the string
func ExecContainsString ¶
ExecContainsString checks that the given command output contains the string.
func ExecNotContainsStdErrorString ¶
ExecNotContainsStdErrorString checks that the given command stdErr output contains the string
func NewTestFor ¶
func NewTestFor(pluginName string) *plugin.PluginDescriptor
NewTestFor creates a plugin descriptor for a test plugin.
Types ¶
type Main ¶
type Main struct {
// Name of the main test.
Name string
// Tests in this main.
Tests []*Test
// Report holds the report for the test.
Report *Report
// Cleanup function.
Cleanup CleanupFunc
// Whether to defer the resource deletion.
DeferDelete bool
// contains filtered or unexported fields
}
Main holds state for multiple command tests.
func NewMain ¶
func NewMain(name string, c *cobra.Command, cleanup CleanupFunc) *Main
NewMain returns a new CLI test.
func (*Main) BuildReport ¶
func (m *Main) BuildReport()
BuildReport will build the report with the current commands.
func (*Main) PrintFailure ¶
func (m *Main) PrintFailure()
PrintFailure prints a main test failure message.
func (*Main) PrintReport ¶
PrintReport prints the report in json|yaml.
func (*Main) PrintSuccess ¶
func (m *Main) PrintSuccess()
PrintSuccess prints a successful main test message.
func (*Main) ReportError ¶
ReportError adds an error result to the report.
func (*Main) ReportResult ¶
ReportResult adds a result to the report.
func (*Main) ReportSuccess ¶
ReportSuccess adds an error result to the report.
func (*Main) ReportTestResult ¶
ReportTestResult adds an error result to the report.
type Report ¶
type Report struct {
// Name of the report.
TestName string `json:"testName"`
// TimeStart at which the test was started.
TimeStart time.Time `json:"timeStart"`
// TimeEnd at which the test was started.
TimeEnd time.Time `json:"timeEnd"`
// Pass tells whether all the tests passed.
Pass bool `json:"pass"`
// Results of the test.
Results []*Result `json:"results"`
}
Report is the report generated from running a CLI test.
type Result ¶
type Result struct {
// Command executed.
Command string `json:"command"`
// Pass tells if command passed execution.
Pass bool `json:"pass"`
// Err holds any error produced.
Err error `json:"err"`
}
Result is the result of an individual CLI test.
type Test ¶
type Test struct {
// Name of the test.
Name string
// Command to test.
Command string
// Result of command test.
Result *Result
// contains filtered or unexported fields
}
Test is a cli test to run.
func (*Test) ExecContainsAnyString ¶
ExecContainsAnyString executes the command and checks if the output contains any of the given set of strings.
func (*Test) ExecContainsErrorString ¶
ExecContainsErrorString executes the command and checks if the output contains the given string.
func (*Test) ExecContainsString ¶
ExecContainsString executes the command and checks if the output contains the given string.
func (*Test) ExecNotContainsStdErrorString ¶
ExecNotContainsStdErrorString executes the command and checks if the StdError contains the given string.
func (*Test) PrintSuccess ¶
func (t *Test) PrintSuccess()
PrintSuccess will print a success message.