httptest

package module
v0.1.16 Latest Latest
Warning

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

Go to latest
Published: Jul 14, 2023 License: Apache-2.0 Imports: 11 Imported by: 2

README

httptest

LICENSE go doc go report Codecov

http uint test

download
  go get -u github.com/snowlyg/httptest@latest
use case

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (

	// default page request params
	GetRequestFunc = NewWithQueryObjectParamFunc(map[string]interface{}{"page": 1, "pageSize": 10})

	// default page request params
	PostRequestFunc = NewWithJsonParamFunc(map[string]interface{}{"page": 1, "pageSize": 10})

	// default login request params
	LoginFunc = NewWithJsonParamFunc(map[string]interface{}{"username": "admin", "password": "123456"})

	// default login response params
	LoginResponse = Responses{
		{Key: "status", Value: http.StatusOK},
		{Key: "message", Value: "OK"},
		{Key: "data",
			Value: Responses{
				{Key: "accessToken", Value: "", Type: "notempty"},
			},
		},
	}
	//LogoutResponse default logout response params
	LogoutResponse = Responses{
		{Key: "status", Value: http.StatusOK},
		{Key: "message", Value: "OK"},
	}

	// SuccessResponse default success response params
	SuccessResponse = Responses{
		{Key: "status", Value: http.StatusOK},
		{Key: "message", Value: "OK"},
	}

	// ResponsePage default data response params
	ResponsePage = Responses{
		{Key: "status", Value: http.StatusOK},
		{Key: "message", Value: "OK"},
		{Key: "data", Value: Responses{
			{Key: "pageSize", Value: 10},
			{Key: "page", Value: 1},
		}},
	}
)

Functions

func Exist

func Exist(object *httpexpect.Object, key string) bool

Exist Check object keys if the key is in the keys array.

func NewWithFileParamFunc added in v0.0.5

func NewWithFileParamFunc(fs []File) paramFunc

NewWithFileParamFunc return req.WithFile

func NewWithJsonParamFunc added in v0.0.5

func NewWithJsonParamFunc(query map[string]interface{}) paramFunc

NewWithJsonParamFunc return req.WithJSON

func NewWithQueryObjectParamFunc added in v0.0.5

func NewWithQueryObjectParamFunc(query map[string]interface{}) paramFunc

NewWithQueryObjectParamFunc query for get method

func Scan added in v0.0.5

func Scan(object *httpexpect.Object, reses ...Responses)

Scan scan data form http response

func Test added in v0.0.5

func Test(value *httpexpect.Value, reses ...interface{})

Test for data test

Types

type Client

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

func Instance added in v0.0.3

func Instance(t *testing.T, handler http.Handler, url ...string) *Client

Instance return test client instance

func (*Client) DELETE

func (c *Client) DELETE(url string, res interface{}, paramFuncs ...paramFunc)

DELETE

func (*Client) DOWNLOAD added in v0.0.4

func (c *Client) DOWNLOAD(url string, res interface{}, paramFuncs ...paramFunc) string

DOWNLOAD

func (*Client) GET

func (c *Client) GET(url string, res interface{}, paramFuncs ...paramFunc)

GET

func (*Client) Login

func (c *Client) Login(url, tokenIndex string, res Responses, paramFuncs ...paramFunc) error

Login for http login

func (*Client) Logout

func (c *Client) Logout(url string, res Responses)

Logout for http logout

func (*Client) POST

func (c *Client) POST(url string, res interface{}, paramFuncs ...paramFunc)

POST

func (*Client) PUT

func (c *Client) PUT(url string, res interface{}, paramFuncs ...paramFunc)

PUT

func (*Client) SetHeaders added in v0.1.0

func (c *Client) SetHeaders(headers map[string]string) *Client

SetHeaders set http request headers

func (*Client) SetStatus added in v0.0.9

func (c *Client) SetStatus(status int) *Client

SetStatus set what's http response stauts want

func (*Client) UPLOAD

func (c *Client) UPLOAD(url string, res interface{}, paramFuncs ...paramFunc)

UPLOAD

type File

type File struct {
	Key    string
	Path   string
	Reader io.Reader
}

type Response

type Response struct {
	Type   string                // httpest type , if empty use  Equal() function to test
	Key    string                // httptest data's key
	Value  interface{}           // httptest data's value
	Length int                   // httptest data's length,when the data are array or map
	Func   func(obj interface{}) // httpest func, you can add your test logic ,can be empty
}

Response

type Responses

type Responses []Response

Responses

func IdKeys

func IdKeys() Responses

IdKeys return Responses with id

func NewResponses added in v0.0.6

func NewResponses(status int, message string, data ...Responses) Responses

NewResponses return Responses

func NewResponsesWithLength added in v0.0.6

func NewResponsesWithLength(status int, message string, data []Responses, length int) Responses

NewResponsesWithLength return Responses with length value for data key

func (Responses) GetFloat64 added in v0.0.6

func (rks Responses) GetFloat64(key ...string) float64

GetFloat64 return float64

func (Responses) GetId

func (res Responses) GetId(key ...string) uint

GetId return id

func (Responses) GetInt

func (rks Responses) GetInt(key ...string) int

GetInt return int value

func (Responses) GetInt32

func (rks Responses) GetInt32(key ...string) int32

GetInt32 return int32.

func (Responses) GetResponse

func (rks Responses) GetResponse(key string) Responses

GetResponsereturn Resposnes value

func (Responses) GetResponses

func (rks Responses) GetResponses(key string) []Responses

GetResponses return Resposnes Array value

func (Responses) GetStrArray

func (rks Responses) GetStrArray(key string) []string

GetStrArray return string array value.

func (Responses) GetString

func (res Responses) GetString(key ...string) string

GetString return string value.

func (Responses) GetUint

func (rks Responses) GetUint(key ...string) uint

GetUint return uint value

func (Responses) Keys

func (res Responses) Keys() []string

Keys return Responses object key array

func (Responses) Scan

func (res Responses) Scan(object *httpexpect.Object)

Scan Scan response data to Responses object.

func (Responses) Test

func (res Responses) Test(value *httpexpect.Value)

Test Test Responses object

Jump to

Keyboard shortcuts

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