netkit

package
v0.0.7 Latest Latest
Warning

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

Go to latest
Published: Oct 12, 2023 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewJSONRequest

func NewJSONRequest(ctx context.Context, method, url string, body interface{}) (*http.Request, error)

NewJSONRequest creates new request with JSON body

func NewQueryRequest

func NewQueryRequest(ctx context.Context, method, url string, queries types.Map) (*http.Request, error)

NewQueryRequest creates request with query strings

func NewUploadRequest

func NewUploadRequest(ctx context.Context, url string, file []byte, fields map[string]string) (*http.Request, error)

NewUploadRequest create a new http upload request

func SendRequest

func SendRequest(r *http.Request) (*http.Response, error)

SendRequest sends general request to a URL and returns HTTP response

Types

type InternalBody

type InternalBody[R any] struct {
	Verdict string    `json:"verdict"`
	Message string    `json:"message"`
	Time    time.Time `json:"time"`
	Data    R         `json:"data"`
}

InternalBody defines struct for internal response body This is for communicate with internal services (rio exposed services)

type Response

type Response[Body any] struct {
	StatusCode int  `json:"status_code"`
	Body       Body `json:"body"`
}

Response is generic response structure Body is data type of the response body

func ExecuteTestCase

func ExecuteTestCase[Body any](t *testing.T, tc *TestCase, engine *gin.Engine) *Response[InternalBody[Body]]

ExecuteTestCase execute test case with gin engine

func Get

func Get[Body any](ctx context.Context, url string) (*Response[Body], error)

Get executes request with GET method Body is structure of response body

func ParseResponse

func ParseResponse[R any](ctx context.Context, r *http.Response) (*Response[R], error)

ParseResponse parses an http response to struct

func PostJSON

func PostJSON[Body any](ctx context.Context, url string, body interface{}) (*Response[Body], error)

PostJSON executes request with POST method and JSON as body, then parse response Body is structure of response body

type ResponseRecorder

type ResponseRecorder struct {
	*httptest.ResponseRecorder
	// contains filtered or unexported fields
}

ResponseRecorder wraps recorder to support CloseNotify

func NewResponseRecorder

func NewResponseRecorder() *ResponseRecorder

NewResponseRecorder returns a new instance

func (*ResponseRecorder) CloseNotify

func (r *ResponseRecorder) CloseNotify() <-chan bool

CloseNotify waits for closed message This is required method for go-gin framework

type TestCase

type TestCase struct {
	Name          string
	Method        string
	Path          string
	AuthToken     string
	Params        types.Map
	Headers       types.Map
	ExpectStatus  int
	ExpectVerdict string
	ExpectHeaders types.Map
	FilePath      string
}

TestCase is a test case for HTTP request

func NewTestCase

func NewTestCase(
	name string,
	method string,
	path string,
	params types.Map,
	expectStatus int,
	expectVerdict string,
) *TestCase

NewTestCase returns a new HTTP test case

Jump to

Keyboard shortcuts

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