mock

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Jan 16, 2023 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ResponseSequentially responseMode = "sequential"
	ResponseRandomly     responseMode = "random"
	DefaultResponse      responseMode = ""
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Delay added in v0.0.29

type Delay struct {
	Min int `yaml:"min" json:"min"`
	Max int `yaml:"max" json:"max"`
}

func (Delay) Validate added in v0.0.29

func (d Delay) Validate() error

func (Delay) Value added in v0.0.29

func (d Delay) Value() int

type Mock

type Mock struct {
	ID     string   `yaml:"id,omitempty" json:"id,omitempty"`
	Name   string   `yaml:"name,omitempty" json:"name,omitempty"`
	Port   string   `yaml:"port,omitempty" json:"port,omitempty"`
	Routes []*Route `yaml:"routes,omitempty" json:"routes,omitempty"`
	Proxy  *Proxy   `yaml:"proxy,omitempty" json:"proxy,omitempty"`
	// all OPTIONS calls are responded with success if AutoCORS is true
	AutoCORS bool `yaml:"auto_cors,omitempty" json:"auto_cors,omitempty"`
	TLS      *TLS `yaml:"tls,omitempty" json:"tls,omitempty"`

	FilePath string `yaml:"-" json:"-"`
	// contains filtered or unexported fields
}

func FromFile

func FromFile(file string, opts ...Option) (*Mock, error)

func FromYaml

func FromYaml(text string, opts ...Option) (*Mock, error)

func New

func New(opts ...Option) *Mock

func (Mock) ApplyDefault added in v0.0.35

func (m Mock) ApplyDefault() Mock

func (Mock) JSON added in v0.0.32

func (m Mock) JSON() (string, error)

func (Mock) ProxyEnabled

func (m Mock) ProxyEnabled() bool

func (Mock) TLSEnabled added in v0.0.17

func (m Mock) TLSEnabled() bool

func (Mock) Validate

func (m Mock) Validate() error

type Operator

type Operator string
const (
	Equal Operator = "equal"
	Regex Operator = "regex"
)

type Option

type Option func(*mockOptions)

func WithIDGeneration

func WithIDGeneration() Option

type Proxy

type Proxy struct {
	Enabled            bool              `yaml:"enabled,omitempty" json:"enabled,omitempty"`
	Host               string            `yaml:"host,omitempty" json:"host"`
	RequestHeaders     map[string]string `yaml:"request_headers,omitempty" json:"request_headers,omitempty"`
	ResponseHeaders    map[string]string `yaml:"response_headers,omitempty" json:"response_headers,omitempty"`
	InsecureSkipVerify bool              `yaml:"insecure_skip_verify,omitempty" json:"insecure_skip_verify,omitempty"`
}

func (Proxy) Validate added in v0.0.35

func (p Proxy) Validate() error

type Response

type Response struct {
	ID              string            `yaml:"id,omitempty" json:"id,omitempty"`
	Status          int               `yaml:"status" json:"status,omitempty"`
	Delay           Delay             `yaml:"delay,omitempty" json:"delay,omitempty"`
	Headers         map[string]string `yaml:"headers,omitempty" json:"headers,omitempty"`
	Body            string            `yaml:"body,omitempty" json:"body,omitempty"`
	FilePath        string            `yaml:"file_path,omitempty" json:"file_path,omitempty"`
	RuleAggregation RuleAggregation   `yaml:"rule_aggregation,omitempty" json:"rule_aggregation,omitempty"`
	Rules           []Rule            `yaml:"rules,omitempty" json:"rules,omitempty"`
	IsDefault       bool              `yaml:"is_default,omitempty" json:"is_default,omitempty"`
}

func (Response) Validate

func (r Response) Validate() error

type Route

type Route struct {
	ID           string       `yaml:"id,omitempty" json:"id,omitempty"`
	Method       string       `yaml:"method" json:"method"`
	Path         string       `yaml:"path" json:"path"`
	Description  string       `yaml:"description" json:"description"`
	ResponseMode responseMode `yaml:"response_mode,omitempty" json:"response_mode,omitempty"`
	Responses    []Response   `yaml:"responses" json:"responses"`
	Disabled     bool         `yaml:"disabled,omitempty" json:"disabled,omitempty"`
}

func (Route) Validate

func (r Route) Validate() error

type Rule

type Rule struct {
	ID       string   `yaml:"id,omitempty" json:"id,omitempty"`
	Target   Target   `yaml:"target" json:"target"`
	Modifier string   `yaml:"modifier" json:"modifier,omitempty"`
	Value    string   `yaml:"value" json:"value"`
	Operator Operator `yaml:"operator" json:"operator"`
}

func (Rule) Validate

func (r Rule) Validate() error

type RuleAggregation

type RuleAggregation string
const (
	Or  RuleAggregation = "or"
	And RuleAggregation = "and"
)

type TLS added in v0.0.17

type TLS struct {
	Enabled     bool   `yaml:"enabled,omitempty" json:"enabled,omitempty"`
	PEMCertPath string `yaml:"pem_cert_path,omitempty" json:"pem_cert_path,omitempty"`
	PEMKeyPath  string `yaml:"pem_key_path,omitempty" json:"pem_key_path,omitempty"`
}

type Target

type Target string
const (
	Header        Target = "header"
	Body          Target = "body"
	QueryString   Target = "query_string"
	Cookie        Target = "cookie"
	RouteParam    Target = "route_param"
	RequestNumber Target = "request_number"
)

Jump to

Keyboard shortcuts

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