assured

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Apr 10, 2020 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

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

Variables

This section is empty.

Functions

func StartApplicationHTTPListener

func StartApplicationHTTPListener(root context.Context, errc chan error, settings Settings)

StartApplicationHTTPListener creates a Go-routine that has an HTTP listener for the application endpoints

Types

type AssuredEndpoints

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

AssuredEndpoints

func NewAssuredEndpoints

func NewAssuredEndpoints(settings Settings) *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
	Port int
	// contains filtered or unexported fields
}

Client

func NewClient

func NewClient(root context.Context, settings Settings) *Client

NewClient creates a new go-rest-assured client

func NewDefaultClient

func NewDefaultClient() *Client

NewDefaultClient creates a new go-rest-assured client with default parameters

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 Settings

type Settings struct {
	Logger         kitlog.Logger
	HTTPClient     http.Client
	Port           int
	TrackMadeCalls bool
}

Settings

Jump to

Keyboard shortcuts

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