Documentation ¶
Index ¶
- Variables
- func CheckStringContains(t *testing.T, got, expected string)
- func CheckStringOmits(t *testing.T, got, expected string)
- func EmptyRun(*cobra.Command, []string)
- func ExecuteCommand(root *cobra.Command, args ...string) (output string, err error)
- func ResetCommandLineFlagSet()
- func ResetConfigManager()
- func RunCommandTests(t *testing.T, cmdTests map[string]CommandTest)
- func SetupConfigManager()
- func SetupContext(contextName string, clientConfig api.ClientConfig, ...)
- func SetupMasterContext()
- func TestingHTTPClient(handler http.Handler) (*http.Client, func())
- type CommandTest
Constants ¶
This section is empty.
Variables ¶
View Source
var ( // ClientConfig mocked for testing ClientConfig = api.ClientConfig{ Authentication: auth, Debug: true, Host: "domain.com", Timeout: "15s", Token: "secret", } )
Functions ¶
func CheckStringContains ¶
CheckStringContains check if string contains the expected value
func CheckStringOmits ¶
CheckStringOmits check if string doesn't contain the expected value
func ExecuteCommand ¶
ExecuteCommand execute a command
func ResetCommandLineFlagSet ¶
func ResetCommandLineFlagSet()
ResetCommandLineFlagSet resets the flagset
func RunCommandTests ¶
func RunCommandTests(t *testing.T, cmdTests map[string]CommandTest)
RunCommandTests runs all set test scenarios *** USAGE ***
func TestFooCommands(t *testing.T) { scenarios := make(map[string]test.CommandTest) scenarios["'Foo' command should throw error without args"] = test.CommandTest{ Cmd: NewRootCommand, CmdArgs: []string{"foo"},11 ShouldContainErrors: []string{`No args set!`}, } scenarios["'Foo' command run successfully with args"] = test.CommandTest{ Cmd: NewRootCommand, CmdArgs: []string{"foo","bar"},11 ShouldContain: []string{`Run smoothly!`}, }
// Both tests will run
test.RunCommandTests(t, scenarios) }
func SetupConfigManager ¶
func SetupConfigManager()
SetupConfigManager setup a new empty config manager if not done already
func SetupContext ¶
func SetupContext(contextName string, clientConfig api.ClientConfig, basicAuth api.BasicAuthentication)
SetupContext add a new context in Config
func SetupMasterContext ¶
func SetupMasterContext()
SetupMasterContext add a new context named "master" in Config
func TestingHTTPClient ¶
TestingHTTPClient starts a httptest.Server that serves the provided handler and returns an http.Client that always dials to this server.
Types ¶
type CommandTest ¶
type CommandTest struct { Setup func() Teardown func() Cmd func() *cobra.Command CmdArgs []string ProcessOutput func(t *testing.T, s string) ShouldContainErrors []string HasCustomError error ShouldContain []string ShouldNotContain []string }
CommandTest struct to define a test scenario
Click to show internal directories.
Click to hide internal directories.