assured

package
v3.1.2 Latest Latest
Warning

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

Go to latest
Published: Oct 10, 2022 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const (
	AssuredStatus         = "Assured-Status"
	AssuredMethod         = "Assured-Method"
	AssuredDelay          = "Assured-Delay"
	AssuredCallbackKey    = "Assured-Callback-Key"
	AssuredCallbackTarget = "Assured-Callback-Target"
	AssuredCallbackDelay  = "Assured-Callback-Delay"
)

Variables

View Source
var DefaultOptions = Options{
	// contains filtered or unexported fields
}

Functions

This section is empty.

Types

type AssuredEndpoints

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

AssuredEndpoints

func NewAssuredEndpoints

func NewAssuredEndpoints(options Options) *AssuredEndpoints

NewAssuredEndpoints creates a new instance of assured endpoints

func (*AssuredEndpoints) ClearAllEndpoint

func (a *AssuredEndpoints) ClearAllEndpoint(ctx context.Context, i interface{}) (interface{}, error)

ClearAllEndpoint is used to clear all assured calls

func (*AssuredEndpoints) ClearEndpoint

func (a *AssuredEndpoints) ClearEndpoint(ctx context.Context, call *Call) (interface{}, error)

ClearEndpoint is used to clear a specific assured call

func (*AssuredEndpoints) GivenCallbackEndpoint

func (a *AssuredEndpoints) GivenCallbackEndpoint(ctx context.Context, call *Call) (interface{}, error)

GivenCallbackEndpoint is used to stub out callbacks for a callback key

func (*AssuredEndpoints) GivenEndpoint

func (a *AssuredEndpoints) GivenEndpoint(ctx context.Context, call *Call) (interface{}, error)

GivenEndpoint is used to stub out a call for a given path

func (*AssuredEndpoints) VerifyEndpoint

func (a *AssuredEndpoints) VerifyEndpoint(ctx context.Context, call *Call) (interface{}, error)

VerifyEndpoint is used to verify a particular call

func (*AssuredEndpoints) WhenEndpoint

func (a *AssuredEndpoints) WhenEndpoint(ctx context.Context, call *Call) (interface{}, error)

WhenEndpoint is used to test the assured calls

func (*AssuredEndpoints) WrappedEndpoint

func (a *AssuredEndpoints) WrappedEndpoint(handler func(context.Context, *Call) (interface{}, error)) endpoint.Endpoint

WrappedEndpoint is used to validate that the incoming request is an assured call

type Call

type Call struct {
	Path       string            `json:"path"`
	Method     string            `json:"method"`
	StatusCode int               `json:"status_code"`
	Delay      int               `json:"delay"`
	Headers    map[string]string `json:"headers"`
	Query      map[string]string `json:"query,omitempty"`
	Response   CallResponse      `json:"response,omitempty"`
	Callbacks  []Callback        `json:"callbacks,omitempty"`
}

Call is a structure containing a request that is stubbed or made

func (Call) ID

func (c Call) ID() string

ID is used as a key when managing stubbed and made calls

func (Call) String

func (c Call) String() string

String converts a Call's Response into a string

type CallResponse

type CallResponse []byte

CallResponse allows control over the Call's Response encoding

func (*CallResponse) UnmarshalJSON

func (response *CallResponse) UnmarshalJSON(data []byte) error

UnmarshalJSON is a custom implementation for JSON Unmarshalling for the CallResponse Unmarshalling will first check if the data is a local filepath that can be read Else it will check if the data is stringified JSON and un-stringify the data to use or Else it will just use the []byte

type CallStore

type CallStore struct {
	sync.Mutex
	// contains filtered or unexported fields
}

func NewCallStore

func NewCallStore() *CallStore

func (*CallStore) Add

func (c *CallStore) Add(call *Call)

func (*CallStore) AddAt

func (c *CallStore) AddAt(key string, call *Call)

func (*CallStore) Clear

func (c *CallStore) Clear(key string)

func (*CallStore) ClearAll

func (c *CallStore) ClearAll()

func (*CallStore) Get

func (c *CallStore) Get(key string) []*Call

func (*CallStore) Rotate

func (c *CallStore) Rotate(call *Call)

type Callback

type Callback struct {
	Target   string            `json:"target"`
	Method   string            `json:"method"`
	Delay    int               `json:"delay,omitempty"`
	Headers  map[string]string `json:"headers"`
	Response CallResponse      `json:"response,omitempty"`
}

Callback is a structure containing a callback that is stubbed

type Client

type Client struct {
	Errc chan error
	Options
}

Client

func NewClient

func NewClient(opts ...Option) *Client

NewClient creates a new go-rest-assured client

func (*Client) Clear

func (c *Client) Clear(method, path string) error

Clear assured calls for a Method and Path

func (*Client) ClearAll

func (c *Client) ClearAll() error

ClearAll clears all assured calls

func (*Client) Close

func (c *Client) Close()

Close is used to close the running service

func (*Client) Given

func (c *Client) Given(calls ...Call) error

Given stubs assured Call(s)

func (*Client) URL

func (c *Client) URL() string

URL returns the url to use to test you stubbed endpoints

func (*Client) Verify

func (c *Client) Verify(method, path string) ([]Call, error)

Verify returns all of the calls made against a stubbed method and path

type Option

type Option func(*Options)

Option is a function on that configures rest assured settings

func WithCallTracking

func WithCallTracking(t bool) Option

WithCallTracking sets the trackMadeCalls option.

func WithContext

func WithContext(c context.Context) Option

WithContext sets the context option.

func WithHTTPClient

func WithHTTPClient(c http.Client) Option

WithHTTPClient sets the http client option.

func WithHost

func WithHost(h string) Option

WithHost sets the host option.

func WithLogger

func WithLogger(l kitlog.Logger) Option

WithLogger sets the logger to be used.

func WithPort

func WithPort(p int) Option

WithPort sets the port option.

func WithTLS

func WithTLS(cert, key string) Option

WithTLS sets the tls options.

type Options

type Options struct {

	// port for the rest assured server to listen on. Defaults to any available port.
	Port int
	// contains filtered or unexported fields
}

Options can be used to configure the rest assured client.

Jump to

Keyboard shortcuts

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