assured

package
v4.4.0 Latest Latest
Warning

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

Go to latest
Published: Jun 29, 2024 License: MIT Imports: 15 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 APIError added in v4.3.0

type APIError struct {
	Error error `json:"error"`
}

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 {
	Options
	// contains filtered or unexported fields
}

Client

func NewClient

func NewClient(opts ...Option) *Client

NewClient creates a new go-rest-assured client

func NewClientServe

func NewClientServe(opts ...Option) *Client

NewClient creates a new go-rest-assured client and starts serving traffic

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() error

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) Serve

func (c *Client) Serve() error

Serve starts the Rest Assured client to begin listening on the application endpoints

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 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 added in v4.1.0

func WithLogger(l *slog.Logger) Option

WithCallTracking sets the trackMadeCalls option.

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