mock

package
v2.8.0+incompatible Latest Latest
Warning

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

Go to latest
Published: Jun 23, 2020 License: MIT Imports: 8 Imported by: 4

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Callback

type Callback struct {
	Delay  Delay  `json:"delay"`
	Method string `json:"method"`
	Url    string `json:"url"`
	HttpHeaders
	Body    string `json:"body"`
	Timeout Delay  `json:"timeout"`
}

type Control

type Control struct {
	Priority     int      `json:"priority"`
	Delay        Delay    `json:"delay"`
	Crazy        bool     `json:"crazy"`
	Scenario     Scenario `json:"scenario"`
	ProxyBaseURL string   `json:"proxyBaseURL"`
	WebHookURL   string   `json:"webHookURL"`
}

type Cookies

type Cookies map[string]string

type Definition

type Definition struct {
	URI         string
	Description string   `json:"description"`
	Request     Request  `json:"request"`
	Response    Response `json:"response"`
	Callback    Callback `json:"callback"`
	Control     Control  `json:"control"`
}

Definition contains the user mock config

type Delay

type Delay struct {
	time.Duration
}

func (*Delay) UnmarshalJSON

func (d *Delay) UnmarshalJSON(data []byte) (err error)

type HTTP

type HTTP struct {
}

HTTP is and adaptor beteewn the http and mock config.

func (HTTP) BuildRequestDefinitionFromHTTP

func (t HTTP) BuildRequestDefinitionFromHTTP(req *http.Request) Request

BuildRequestDefinitionFromHTTP Read the request config and return a mock request.

func (HTTP) WriteHTTPResponseFromDefinition

func (t HTTP) WriteHTTPResponseFromDefinition(fr *Response, w http.ResponseWriter)

WriteHTTPResponseFromDefinition read a mock response and write a http response.

type HttpHeaders

type HttpHeaders struct {
	Headers Values  `json:"headers"`
	Cookies Cookies `json:"cookies"`
}

type MessageTranslator

type MessageTranslator interface {
	MockRequestBuilder
	MockResponseWriter
}

MessageTranslator defines the translator contract between http and mock and viceversa. this translation decople the mock checker from the specific http implementation.

type MockRequestBuilder

type MockRequestBuilder interface {
	BuildRequestDefinitionFromHTTP(req *http.Request) Request
}

MockRequestBuilder defines the translator from http.Request to config.Request

type MockResponseWriter

type MockResponseWriter interface {
	WriteHTTPResponseFromDefinition(fr *Response, w http.ResponseWriter)
}

MockResponseWriter defines the translator from config.Response to http.ResponseWriter

type Request

type Request struct {
	Scheme                string `json:"scheme"`
	Host                  string `json:"host"`
	Port                  string `json:"port"`
	Method                string `json:"method"`
	Path                  string `json:"path"`
	QueryStringParameters Values `json:"queryStringParameters"`
	Fragment              string `json:"fragment"`
	HttpHeaders
	Body string `json:"body"`
}

type Response

type Response struct {
	StatusCode int `json:"statusCode"`
	HttpHeaders
	Body string `json:"body"`
}

type Scenario

type Scenario struct {
	Name          string   `json:"name"`
	RequiredState []string `json:"requiredState"`
	NewState      string   `json:"newState"`
}

type Values

type Values map[string][]string

Jump to

Keyboard shortcuts

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