client

package
v0.17.0 Latest Latest
Warning

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

Go to latest
Published: Apr 5, 2024 License: MPL-2.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrTODO is returned when a feature is not yet implemented
	ErrTODO = errors.New("TODO: This feature is not implemented yet")

	// ErrNotFound is returned when an api call returns 404
	ErrNotFound = errors.New("Resource not found")

	// ErrFailed represents errors occurred during API calls to Tyk.
	ErrFailed = errors.New("Failed api call")

	ErrMissingAPIID = errors.New("Missing API ID")

	ErrMissingPolicyID = errors.New("Missing Policy ID")
)

Functions

func AddHeaders

func AddHeaders(q map[string]string) func(*http.Request)

func AddQuery

func AddQuery(q url.Values) func(*http.Request)

AddQuery call back for adding url queries

func BeforeRequest

func BeforeRequest(r *http.Request)

func Call

func Call(ctx context.Context, method, url string, body io.Reader, fn ...func(*http.Request)) (*http.Response, error)

func CallJSON

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

func Data

func Data(o interface{}) func(*http.Response, error) error

func Delete

func Delete(ctx context.Context, url string, body io.Reader, fn ...func(*http.Request)) (*http.Response, error)

func Do

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

func Error

func Error(res *http.Response) error

Error dumps whole response plus body and return it as an error

func Get

func Get(ctx context.Context, url string, body io.Reader, fn ...func(*http.Request)) (*http.Response, error)

func GetTykMode added in v0.16.0

func GetTykMode(ctx context.Context) environment.Env

func IgnoreNotFound

func IgnoreNotFound(err error) error

IgnoreNotFound returns nil if err is ErrNotFound

func IsNotFound

func IsNotFound(err error) bool

IsNotFound returns true if err is ErrNotFound

func IsTODO

func IsTODO(err error) bool

func JSON

func JSON(res *http.Response, o interface{}) error

func Join

func Join(parts ...string) string

func JoinURL

func JoinURL(base string, parts ...string) string

JoinURL returns addition of parts to the base e.URL

func LError

func LError(ctx context.Context, err error, msg string, kv ...interface{})

func LInfo

func LInfo(ctx context.Context, msg string, kv ...interface{})

func Post

func Post(ctx context.Context, url string, body io.Reader, fn ...func(*http.Request)) (*http.Response, error)

func PostJSON

func PostJSON(ctx context.Context, url string, body interface{}, fn ...func(*http.Request)) (*http.Response, error)

func PutJSON

func PutJSON(ctx context.Context, url string, body interface{}, fn ...func(*http.Request)) (*http.Response, error)

func Request

func Request(ctx context.Context, method, url string, body io.Reader) (*http.Request, error)

func Result

func Result(res *http.Response, err error) (*model.Result, error)

func RunRequestKase

func RunRequestKase(t *testing.T, e *environment.Env, fn func(context.Context) error, kase ...Kase)

RunRequestKase this helps check if we are sending a correct request. This assumes fn will only perform a single API call, this ignores the response it only validates we are sending correct path/method/headers

func SetContext

func SetContext(ctx context.Context, rctx Context) context.Context

func SetHeaders

func SetHeaders(q map[string]string) func(*http.Request)

Types

type Context

type Context struct {
	Env           environment.Env
	Log           logr.Logger
	BeforeRequest func(*http.Request)
	Do            func(*http.Request) (*http.Response, error)
}

Context information needed to make a successful http api call.

func GetContext

func GetContext(ctx context.Context) Context

type Kase

type Kase struct {
	Name     string
	Request  RequestKase
	Response *ResponseKase
}

Kase a single test case for an API call.

type RequestKase

type RequestKase struct {
	Path     string
	Method   string
	Headers  map[string]string
	Callback func(*testing.T, *http.Request)
}

type ResponseKase

type ResponseKase struct {
	Headers  map[string]string
	Body     string
	Callback func(*testing.T, *http.Response)
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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