testutil

package
v0.1.9 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 13, 2019 License: MIT Imports: 5 Imported by: 1

Documentation

Index

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.1.6

func MockEnvValue(key, val string, fn func(nv string))

MockEnvValue will store old env value, set new val. will restore old value on end.

func MockEnvValues added in v0.1.6

func MockEnvValues(kvMap map[string]string, fn func())

MockEnvValues will store old env value, set new val. will restore old value on end.

func MockRequest

func MockRequest(h http.Handler, method, path string, data *MD) *httptest.ResponseRecorder

MockRequest mock an HTTP Request Usage:

handler := router.New()
res := mockRequest(handler, "GET", "/path", nil)
// with data
body := strings.NewReader("string ...")
res := mockRequest(handler, "GET", "/path", &MD{Body: "data", Headers: M{"x-head": "val"}})

func RestoreStdout

func RestoreStdout() (s string)

RestoreStdout restore os.Stdout

func RewriteStdout

func RewriteStdout()

RewriteStdout rewrite os.Stdout Usage:

RewriteStdout()
fmt.Println("Hello, playground")
msg := RestoreStdout()

Types

type M

type M map[string]string

M short name for map

type MD

type MD struct {
	// Body body
	Body io.Reader
	// Headers headers
	Headers M
	// BeforeSend callback
	BeforeSend func(req *http.Request)
}

MD simple request data

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL