Documentation ¶
Index ¶
- func DiscardStdout() error
- func MockEnvValue(key, val string, fn func(nv string))
- func MockEnvValues(kvMap map[string]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 ¶
MockEnvValue will store old env value, set new val. will restore old value on end.
func MockEnvValues ¶
MockEnvValues will store old env value, set new val. will restore old value on end.
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 ¶
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 RewriteStderr ¶
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.