Documentation ¶
Index ¶
- Variables
- func AssertDBCount(t *testing.T, gdb *gorm.DB, expected int64)
- func AssertDBHas(t *testing.T, gdb *gorm.DB, cols Columns)
- func AssertDBMissing(t *testing.T, gdb *gorm.DB, cols Columns)
- func AssertResp(resp *httpexpect.Response, r Expected)
- func AssertRespCode(resp *httpexpect.Response, code int)
- func AssertRespData(resp *httpexpect.Response, data interface{})
- func AssertRespDataCheck(resp *httpexpect.Response, dataChecker func(value *httpexpect.Value))
- func AssertRespMsg(resp *httpexpect.Response, msg string)
- func AssertRespMsgContains(resp *httpexpect.Response, msg string)
- func AssertRespStatus(resp *httpexpect.Response, status int)
- func DryRunSession(t *testing.T) *gorm.DB
- func DumpStderr() string
- func DumpStdout() string
- func HandleCommand(handler func(args []string, expectStderr bool))
- func RedirectStderr()
- func RedirectStdout()
- func RunCobraCmd(cmd *cobra.Command, args ...string) (string, error)
- func SetupCmd()
- func SetupCmdError()
- func SetupCmdStderr()
- func SetupEnvs(envs Envs)
- func SetupExecLookPath()
- func SetupExecLookPathError()
- func SetupGormDB(t *testing.T, dst ...interface{}) *gorm.DB
- func SetupOsExit(override ...func(code int))
- func SetupServer(t *testing.T, registerRoutes func(app *fiber.App)) *httpexpect.Expect
- func TeardownCmd()
- func TeardownEnvs()
- func TeardownExecLookPath()
- func TeardownOsExit()
- type Columns
- type DisabledGormLogger
- func (DisabledGormLogger) Error(context.Context, string, ...interface{})
- func (DisabledGormLogger) Info(context.Context, string, ...interface{})
- func (DisabledGormLogger) LogMode(logger.LogLevel) logger.Interface
- func (DisabledGormLogger) Trace(context.Context, time.Time, func() (string, int64), error)
- func (DisabledGormLogger) Warn(context.Context, string, ...interface{})
- type Envs
- type Expected
Constants ¶
This section is empty.
Variables ¶
var ErrLookPath = errors.New("deck: look path error")
ErrLookPath means that error occurs when calling ExecLookPath.
var ErrorHandler = fiberx.ErrHandler
ErrorHandler is Dawn's error handler
var ExecCommand = func(name string, arg ...string) *exec.Cmd { return mockExecCommand(name, arg...) }
ExecCommand is a wrapper for exec.Command.
var ExecLookPath = func(file string) (string, error) { return mockExecLookPath(file) }
ExecLookPath is a wrapper for exec.LookPath.
var OsExit = func(code int) { mockOsExit(code) }
OsExit is a wrapper for os.Exit.
var Stderr = os.Stderr
Stderr is a wrapper for os.Stderr.
var Stdout = os.Stdout
Stdout is a wrapper for os.Stdout.
Functions ¶
func AssertDBCount ¶ added in v0.0.4
AssertDBCount asserts db has specific count.
func AssertDBHas ¶ added in v0.0.4
AssertDBHas asserts db has data with specific query condition.
func AssertDBMissing ¶ added in v0.0.4
AssertDBMissing asserts db misses data with specific query condition.
func AssertResp ¶ added in v0.0.3
func AssertResp(resp *httpexpect.Response, r Expected)
AssertResp asserts response with an Expected instance
func AssertRespCode ¶ added in v0.0.3
func AssertRespCode(resp *httpexpect.Response, code int)
AssertRespCode asserts response with an expected business code
func AssertRespData ¶ added in v0.0.3
func AssertRespData(resp *httpexpect.Response, data interface{})
AssertRespData asserts response with an expected data
func AssertRespDataCheck ¶ added in v0.0.3
func AssertRespDataCheck(resp *httpexpect.Response, dataChecker func(value *httpexpect.Value))
AssertRespDataCheck asserts response with an expected data checker
func AssertRespMsg ¶ added in v0.0.3
func AssertRespMsg(resp *httpexpect.Response, msg string)
AssertRespMsg asserts response with an expected message
func AssertRespMsgContains ¶ added in v0.0.3
func AssertRespMsgContains(resp *httpexpect.Response, msg string)
AssertRespMsgContains asserts response contains an expected message
func AssertRespStatus ¶ added in v0.0.3
func AssertRespStatus(resp *httpexpect.Response, status int)
AssertRespStatus asserts response with an expected status code
func DryRunSession ¶ added in v0.0.4
DryRunSession gets a gorm session in dry run mode.
func DumpStderr ¶
func DumpStderr() string
DumpStderr dumps output from Stderr and restores it to the original one.
func DumpStdout ¶
func DumpStdout() string
DumpStdout dumps output from Stdout and restores it to the original one.
func HandleCommand ¶
HandleCommand handles every command wanted help
func RunCobraCmd ¶
RunCobraCmd executes a cobra command and get output and error
func SetupCmd ¶
func SetupCmd()
SetupCmd mocks ExecCommand. Must create one test function named TestHelperCommand in a package and use HandleCommand in it.
func SetupCmdError ¶ added in v0.0.2
func SetupCmdError()
SetupErrorCmd mocks ExecCommand and when running the returned command, always get an error. Must create one test function named TestHelperCommand in a package and use HandleCommand in it.
func SetupCmdStderr ¶ added in v0.0.2
func SetupCmdStderr()
SetupStderrCmd mocks ExecCommand. Must create one test function named TestHelperCommand in a package and use HandleCommand in it. Besides, the second parameter of the handler function in HandleCommand will be true.
func SetupExecLookPathError ¶ added in v0.0.2
func SetupExecLookPathError()
SetupExecLookPathError mocks ExecLookPath and always return an error.
func SetupGormDB ¶ added in v0.0.4
SetupGormDB gets gorm.DB instance. Passed in models will be auto migrated.
func SetupServer ¶ added in v0.0.3
SetupServer registers routes and gets and httpexpect.Expect instance
func TeardownExecLookPath ¶
func TeardownExecLookPath()
TeardownExecLookPath restores ExecLookPath to the original one.
Types ¶
type Columns ¶ added in v0.0.4
type Columns map[string]interface{}
Columns is a condition struct for query
type DisabledGormLogger ¶ added in v0.0.4
type DisabledGormLogger struct{}
DisabledGormLogger implements gorm logger interface
func (DisabledGormLogger) Error ¶ added in v0.0.4
func (DisabledGormLogger) Error(context.Context, string, ...interface{})
Error print error messages
func (DisabledGormLogger) Info ¶ added in v0.0.4
func (DisabledGormLogger) Info(context.Context, string, ...interface{})
Info print info messages
func (DisabledGormLogger) LogMode ¶ added in v0.0.4
func (DisabledGormLogger) LogMode(logger.LogLevel) logger.Interface
LogMode is log mode
type Expected ¶ added in v0.0.3
type Expected struct { // Status is response status code Status int // Code is business code Code int // Msg is response message Msg string // Contain indicates Contain bool // Data is response data Data interface{} // DataChecker is a function which gives you ability // to make assertion with data DataChecker func(data *httpexpect.Value) `json:"-"` }
Expected holds everything need to assert