ytest

package
v0.7.5 Latest Latest
Warning

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

Go to latest
Published: Feb 13, 2024 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	GopPackage = "github.com/goplus/yap/test"
)
View Source
const (
	Gopo_Request_Ret = ".Send,.RetWith"
)

Variables

This section is empty.

Functions

func Bearer added in v0.7.3

func Bearer(token string) auth.RTComposer

Bearer creates a Bearer Authorization by specified token.

func Form

func Form(m map[string]any) (ret url.Values)

Form encodes a map value into string in form format.

func Gopt_App_Main

func Gopt_App_Main(app interface{ initApp() *App }, workers ...interface{ initCase(*App, CaseT) })

Gopt_App_Main is required by Go+ compiler as the Main entry of a YAP testing project.

func Gopt_App_TestMain added in v0.7.2

func Gopt_App_TestMain(app interface{ initApp() *App }, m *testing.M)

Gopt_App_TestMain is required by Go+ compiler as the TestMain entry of a YAP testing project.

func Gopt_Case_TestMain added in v0.7.2

func Gopt_Case_TestMain(c interface{ initCase(*App, CaseT) }, t *testing.T)

Gopt_Case_TestMain is required by Go+ compiler as the entry of a YAP test case.

func JsonEncode

func JsonEncode(v any) string

JsonEncode encodes a value into string in json format.

Types

type App

type App struct {
	// contains filtered or unexported fields
}

func (*App) Host added in v0.7.2

func (p *App) Host(host, real string)

Host replaces a host into real. For example:

host "https://example.com" "http://localhost:8080"
host "http://example.com" "http://localhost:8888"

func (*App) Mock added in v0.7.3

func (p *App) Mock(host string, app yap.AppType)

Mock runs a YAP server by mockhttp.

func (*App) RunMock added in v0.7.3

func (p *App) RunMock(host string, h http.Handler)

RunMock runs a HTTP server by mockhttp.

func (*App) RunTestServer added in v0.7.3

func (p *App) RunTestServer(host string, h http.Handler)

RunTestServer runs a HTTP server by httptest.Server.

func (*App) TestServer added in v0.7.3

func (p *App) TestServer(host string, app yap.AppType)

TestServer runs a YAP server by httptest.Server.

type Case

type Case struct {
	*Request
	*App
	test.Case

	DefaultHeader http.Header
}

func (*Case) DELETE added in v0.7.3

func (p *Case) DELETE(url string) *Request

DELETE is a shortcut for Req(http.MethodDelete, url)

func (*Case) GET added in v0.7.3

func (p *Case) GET(url string) *Request

GET is a shortcut for Req(http.MethodGet, url)

func (*Case) Get

func (p *Case) Get(url string) *Request

Get is a shortcut for Req(http.MethodGet, url)

func (*Case) HEAD added in v0.7.3

func (p *Case) HEAD(url string) *Request

HEAD is a shortcut for Req(http.MethodHead, url)

func (*Case) Head added in v0.7.3

func (p *Case) Head(url string) *Request

Head is a shortcut for Req(http.MethodHead, url)

func (*Case) OPTIONS added in v0.7.3

func (p *Case) OPTIONS(url string) *Request

OPTIONS is a shortcut for Req(http.MethodOptions, url)

func (*Case) Options added in v0.7.3

func (p *Case) Options(url string) *Request

Options is a shortcut for Req(http.MethodOptions, url)

func (*Case) PATCH added in v0.7.3

func (p *Case) PATCH(url string) *Request

PATCH is a shortcut for Req(http.MethodPatch, url)

func (*Case) POST added in v0.7.3

func (p *Case) POST(url string) *Request

POST is a shortcut for Req(http.MethodPost, url)

func (*Case) PUT added in v0.7.3

func (p *Case) PUT(url string) *Request

PUT is a shortcut for Req(http.MethodPut, url)

func (*Case) Patch added in v0.7.3

func (p *Case) Patch(url string) *Request

Patch is a shortcut for Req(http.MethodPatch, url)

func (*Case) Post

func (p *Case) Post(url string) *Request

Post is a shortcut for Req(http.MethodPost, url)

func (*Case) Put added in v0.7.3

func (p *Case) Put(url string) *Request

Put is a shortcut for Req(http.MethodPut, url)

func (*Case) Req__0 added in v0.7.3

func (p *Case) Req__0(method, url string) *Request

Req create a new request given a method and url.

func (*Case) Req__1 added in v0.7.3

func (p *Case) Req__1() *Request

Req returns current request object.

func (*Case) T added in v0.7.3

func (p *Case) T() CaseT

T returns the testing object.

type CaseT added in v0.7.3

type CaseT = test.CaseT

type Request

type Request struct {
	// contains filtered or unexported fields
}

func (*Request) Auth

func (p *Request) Auth(auth auth.RTComposer) *Request

Auth sets an Authorization for this request.

func (*Request) Binary

func (p *Request) Binary(body any) *Request

func (*Request) Body

func (p *Request) Body(bodyType string, body any) *Request

Body sets request body for this request (if request is not sended), or matches response body of this request (after response is returned). Here body can be: string, Var(string), []byte, RequestBody.

func (*Request) Form

func (p *Request) Form(body any) *Request

func (*Request) Header__0 added in v0.7.3

func (p *Request) Header__0(key string, value any) *Request

Header sets a Header for this request (if request is not sended), or matches a Header for response of this request (after response is returned). Here value can be: string, []string, Var(string), Var([]string).

func (*Request) Header__1 added in v0.7.3

func (p *Request) Header__1() http.Header

Header returns header of current request.

func (*Request) Json

func (p *Request) Json(body any) *Request

body can be:

  • map[string]any, Var(map[string]any), []any, Var([]any),
  • []string, Var([]string), string, Var(string), int, Var(int),
  • bool, Var(bool), float64, Var(float64).

func (*Request) Resp

func (p *Request) Resp() *Response

func (*Request) RetWith

func (p *Request) RetWith(code any) *Request

func (*Request) Send

func (p *Request) Send() *Request

func (*Request) Text

func (p *Request) Text(body any) *Request

func (*Request) WithBinary

func (p *Request) WithBinary(bodyType string, body []byte) *Request

func (*Request) WithBody

func (p *Request) WithBody(bodyType string, body RequestBody) *Request

func (*Request) WithBodyEx

func (p *Request) WithBodyEx(bodyType string, body any) *Request

func (*Request) WithForm

func (p *Request) WithForm(body url.Values) *Request

func (*Request) WithFormEx

func (p *Request) WithFormEx(body any) *Request

func (*Request) WithHeader

func (p *Request) WithHeader(key string, value any) *Request

WithHeader sets a Header for this request.

func (*Request) WithJson

func (p *Request) WithJson(body any) *Request

func (*Request) WithText

func (p *Request) WithText(bodyType, body string) *Request

type RequestBody

type RequestBody interface {
	io.Reader
	io.Seeker
	Size() int64
}

type Response

type Response struct {
	// contains filtered or unexported fields
}

func (*Response) Body added in v0.7.2

func (p *Response) Body() (ret any)

Body returns response body decoded according Content-Type.

func (*Response) Code

func (p *Response) Code() int

Code returns the status code of this response.

func (*Response) Header

func (p *Response) Header() http.Header

Header returns header of this response.

func (*Response) RawBody added in v0.7.3

func (p *Response) RawBody() []byte

RawBody returns raw response body as []byte (byte slice).

Directories

Path Synopsis
jwt
demo
_example command
basic command
foo command
jwtdemo command

Jump to

Keyboard shortcuts

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