Documentation ¶
Index ¶
- func DiscardStdout() error
- func MockCleanOsEnv(mp map[string]string, fn func())
- func MockEnvValue(key, val string, fn func(nv string))
- func MockEnvValues(kvMap map[string]string, fn func())
- func MockOsEnv(mp map[string]string, fn func())
- func MockOsEnvByText(envText string, fn func())
- func MockRequest(h http.Handler, method, path string, data *MD) *httptest.ResponseRecorder
- func NewHttpRequest(method, path string, data *MD) *http.Request
- func RestoreStderr(printData ...bool) (s string)
- func RestoreStdout(printData ...bool) (s string)
- func RewriteStderr()
- func RewriteStdout()
- type Buffer
- type M
- type MD
- type TestWriter
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DiscardStdout ¶
func DiscardStdout() error
DiscardStdout Discard os.Stdout output
Usage:
DiscardStdout() fmt.Println("Hello, playground") RestoreStdout()
func MockCleanOsEnv ¶ added in v0.5.5
MockCleanOsEnv by env map data.
will clear all old ENV data, use given data map. will recover old ENV after fn run.
func MockEnvValue ¶ added in v0.1.6
MockEnvValue will store old env value, set new val. will restore old value on end.
func MockEnvValues ¶ added in v0.1.6
MockEnvValues will store old env value, set new val. will restore old value on end.
func MockOsEnvByText ¶ added in v0.3.13
func MockOsEnvByText(envText string, fn func())
MockOsEnvByText by env text string. will clear all old ENV data, use given data map. will recover old ENV after fn run.
func MockRequest ¶
MockRequest mock an HTTP Request
Usage:
handler := router.New() res := MockRequest(handler, "GET", "/path", nil) // with data 1 body := strings.NewReader("string ...") res := MockRequest(handler, "POST", "/path", &MD{ Body: body, Headers: M{"x-head": "val"} }) // with data 2 res := MockRequest(handler, "POST", "/path", &MD{ BodyString: "data string", Headers: M{"x-head": "val"} })
func NewHttpRequest ¶ added in v0.3.6
NewHttpRequest for http testing Usage:
req := NewHttpRequest("GET", "/path", nil) // with data 1 body := strings.NewReader("string ...") req := NewHttpRequest("POST", "/path", &MD{ Body: body, Headers: M{"x-head": "val"} }) // with data 2 req := NewHttpRequest("POST", "/path", &MD{ BodyString: "data string", Headers: M{"x-head": "val"} })
func RestoreStderr ¶ added in v0.2.10
RestoreStderr restore os.Stderr
func RestoreStdout ¶
RestoreStdout restore os.Stdout
func RewriteStderr ¶ added in v0.2.10
func RewriteStderr()
RewriteStderr rewrite os.Stderr
Usage:
RewriteStderr() fmt.Fprintln(os.Stderr, "Hello, playground") msg := RestoreStderr()
func RewriteStdout ¶
func RewriteStdout()
RewriteStdout rewrite os.Stdout
Usage:
RewriteStdout() fmt.Println("Hello, playground") msg := RestoreStdout()
Types ¶
type Buffer ¶ added in v0.5.6
Buffer wrap and extends the bytes.Buffer
func (*Buffer) ResetAndGet ¶ added in v0.5.6
ResetAndGet buffer string.
func (*Buffer) WriteAny ¶ added in v0.5.6
func (b *Buffer) WriteAny(vs ...interface{})
WriteAny method
func (*Buffer) WriteString ¶ added in v0.5.6
WriteString rewrite
type MD ¶
type MD struct { // Headers headers Headers M // Body body. eg: strings.NewReader("name=inhere") Body io.Reader // BodyString quick add body. BodyString string // BeforeSend callback BeforeSend func(req *http.Request) }
MD simple request data
type TestWriter ¶ added in v0.5.3
type TestWriter struct { Buffer // ErrOnWrite return error on write, useful for testing ErrOnWrite bool // ErrOnFlush return error on flush, useful for testing ErrOnFlush bool // ErrOnClose return error on close, useful for testing ErrOnClose bool }
TestWriter struct, useful for testing
func (*TestWriter) SetErrOnClose ¶ added in v0.5.6
func (w *TestWriter) SetErrOnClose()
SetErrOnClose method
func (*TestWriter) SetErrOnFlush ¶ added in v0.5.6
func (w *TestWriter) SetErrOnFlush()
SetErrOnFlush method
func (*TestWriter) SetErrOnWrite ¶ added in v0.5.6
func (w *TestWriter) SetErrOnWrite()
SetErrOnWrite method