Documentation ¶
Index ¶
- func DiscardStdout() error
- 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() (s string)
- func RestoreStdout() (s string)
- func RewriteStderr()
- func RewriteStdout()
- type M
- type MD
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 MockEnvValue ¶ added in v0.4.1
MockEnvValue will store old env value, set new val. will restore old value on end.
func MockEnvValues ¶ added in v0.4.1
MockEnvValues will store old env value, set new val. will restore old value on end.
func MockOsEnv ¶ added in v0.4.1
MockOsEnv by env map data. clear all old ENV data, use given data map, will recover old ENV after fn run.
func MockOsEnvByText ¶ added in v0.4.1
func MockOsEnvByText(envText string, fn func())
MockOsEnvByText by env text string. 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.4.1
NewHttpRequest for http testing Usage:
req := NewHttpRequest(handler, "GET", "/path", nil) // with data 1 body := strings.NewReader("string ...") req := NewHttpRequest(handler, "POST", "/path", &MD{ Body: body, Headers: M{"x-head": "val"} }) // with data 2 req := NewHttpRequest(handler, "POST", "/path", &MD{ BodyString: "data string", Headers: M{"x-head": "val"} })
func RestoreStderr ¶ added in v0.4.1
func RestoreStderr() (s string)
RestoreStderr restore os.Stderr
func RewriteStderr ¶ added in v0.4.1
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 ¶
Click to show internal directories.
Click to hide internal directories.