endpoint

package
v0.7.4 Latest Latest
Warning

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

Go to latest
Published: Nov 7, 2025 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultPrefix = "/gonkex/"

DefaultPrefix is default prefix for all HelperEndpoints in case if you not override this value in Runner configuration.

Variables

This section is empty.

Functions

func NewRequest added in v0.6.5

func NewRequest(host string, test models.TestInterface) (*http.Request, string, error)

func SelectEndpoint

func SelectEndpoint(m EndpointMap, prefix, path string, req *http.Request,
	services *mocks.Mocks, meta MetaProvider) (*http.Response, error)

Types

type Endpoint

type Endpoint func(Helper) error

type EndpointMap

type EndpointMap map[string]Endpoint

type Format added in v0.7.0

type Format int
const (
	FormatJson Format = iota
	FormatYaml
	FormatText
)

type Helper

type Helper interface {
	// GetHeaders returns all request headers.
	GetHeaders() map[string][]string
	// GetPath returns request path without Prefix
	GetPath() string

	// GetRequest unmarshals the request body into the provided interface using the specified format (JSON or YAML).
	//
	// Parameters:
	//   - v: Pointer to the struct where the request data should be unmarshaled
	//   - format: The format to use for unmarshaling (FormatJson or FormatYaml)
	GetRequest(v interface{}, format Format) error
	// GetRequestRaw returns the raw request body bytes without any processing.
	GetRequestRaw() []byte

	// SetResponseFormat sets the format that will be used for response serialization.
	// This affects how SetResponse marshals data and what content type is set.
	SetResponseFormat(format Format)
	// SetResponse marshals the provided data into the response body using
	// the currently configured format (set via SetResponseFormat).
	//
	// Parameters:
	//   - v: The data to marshal into the response body
	SetResponse(v interface{}) error
	// SetResponseRaw sets the response body to the provided raw bytes.
	// This bypasses any marshaling and sets the response data directly.
	SetResponseRaw(response []byte)

	// SetStatusCode sets the HTTP response status code.
	SetStatusCode(code int)
	// SetContentType sets custom content type to HTTP response.
	SetContentType(contentType string)

	// GetMocksTransport returns http.RoundTripper, which routes the request to the
	// appropriate mock service based on the hostname in the request URL.
	GetMocksTransport() http.RoundTripper
	// GetMockAddr returns address of mock with specified name.
	GetMockAddr(name string) string
	// GetMeta returns meta field value from current test.
	GetMeta(key string) interface{}
}

type MetaProvider added in v0.4.6

type MetaProvider interface {
	GetMeta(key string) interface{}
}

Jump to

Keyboard shortcuts

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