testutil

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Mar 17, 2019 License: MIT Imports: 5 Imported by: 0

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