types

package
v0.0.0-...-29b5a33 Latest Latest
Warning

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

Go to latest
Published: Mar 15, 2024 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	StatusSmockerInternalError         = 600
	StatusSmockerEngineExecutionError  = 601
	StatusSmockerProxyRedirectionError = 602
	StatusSmockerMockNotFound          = 666

	SmockerInternalError         = "Smocker internal error"
	SmockerEngineExecutionError  = "Error during template engine execution"
	SmockerProxyRedirectionError = "Error during request redirection"
	SmockerMockNotFound          = "No mock found matching the request"
	SmockerMockExceeded          = "Matching mock found but was exceeded"
)
View Source
const ContextKey = "Context"
View Source
const (
	DefaultMatcher = "ShouldEqual"
)

Variables

View Source
var MockNotFound = fmt.Errorf("mock not found")
View Source
var SessionNotFound = fmt.Errorf("session not found")

Functions

func ShouldBeEmpty

func ShouldBeEmpty(value interface{}, patterns ...interface{}) string

func ShouldMatch

func ShouldMatch(value interface{}, patterns ...interface{}) string

func ShouldNotBeEmpty

func ShouldNotBeEmpty(value interface{}, patterns ...interface{}) string

func ShouldNotMatch

func ShouldNotMatch(value interface{}, patterns ...interface{}) string

Types

type Assertion

type Assertion func(actual interface{}, expected ...interface{}) string

type BodyMatcher

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

func (BodyMatcher) MarshalJSON

func (bm BodyMatcher) MarshalJSON() ([]byte, error)

func (BodyMatcher) MarshalYAML

func (bm BodyMatcher) MarshalYAML() (interface{}, error)

func (BodyMatcher) Match

func (bm BodyMatcher) Match(headers http.Header, value string) bool

func (*BodyMatcher) UnmarshalJSON

func (bm *BodyMatcher) UnmarshalJSON(data []byte) error

func (*BodyMatcher) UnmarshalYAML

func (bm *BodyMatcher) UnmarshalYAML(unmarshal func(interface{}) error) error

type Context

type Context struct {
	MockID   string `json:"mock_id,omitempty"`
	MockType string `json:"mock_type,omitempty"`
	Delay    string `json:"delay,omitempty"`
}

type Delay

type Delay struct {
	Min time.Duration `json:"min,omitempty" yaml:"min,omitempty"`
	Max time.Duration `json:"max,omitempty" yaml:"max,omitempty"`
}

func (*Delay) UnmarshalJSON

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

func (*Delay) UnmarshalYAML

func (d *Delay) UnmarshalYAML(unmarshal func(interface{}) error) error

type DynamicMockResponse

type DynamicMockResponse struct {
	Engine Engine `json:"engine" yaml:"engine"`
	Script string `json:"script" yaml:"script"`
}

type Engine

type Engine string
const (
	GoTemplateEngineID     Engine = "go_template"
	GoTemplateYamlEngineID Engine = "go_template_yaml"
	GoTemplateJsonEngineID Engine = "go_template_json"
	LuaEngineID            Engine = "lua"
)

func (Engine) IsValid

func (e Engine) IsValid() bool

type Entry

type Entry struct {
	Context  Context  `json:"context"`
	Request  Request  `json:"request"`
	Response Response `json:"response"`
}

type GraphConfig

type GraphConfig struct {
	SrcHeader  string `query:"src"`
	DestHeader string `query:"dest"`
}

type GraphEntry

type GraphEntry struct {
	Type    string    `json:"type"`
	Message string    `json:"message"`
	From    string    `json:"from"`
	To      string    `json:"to"`
	Date    time.Time `json:"date"`
}

type GraphHistory

type GraphHistory []GraphEntry

func (GraphHistory) Len

func (p GraphHistory) Len() int

func (GraphHistory) Less

func (p GraphHistory) Less(i, j int) bool

func (GraphHistory) Swap

func (p GraphHistory) Swap(i, j int)

type History

type History []*Entry

func (History) Clone

func (h History) Clone() History

type MapStringSlice

type MapStringSlice map[string]StringSlice

type Mock

type Mock struct {
	Request         MockRequest          `json:"request,omitempty" yaml:"request"`
	Response        *MockResponse        `json:"response,omitempty" yaml:"response,omitempty"`
	Context         *MockContext         `json:"context,omitempty" yaml:"context,omitempty"`
	State           *MockState           `json:"state,omitempty" yaml:"state,omitempty"`
	DynamicResponse *DynamicMockResponse `json:"dynamic_response,omitempty" yaml:"dynamic_response,omitempty"`
	Proxy           *MockProxy           `json:"proxy,omitempty" yaml:"proxy,omitempty"`
}

func (*Mock) CloneAndReset

func (m *Mock) CloneAndReset() *Mock

func (*Mock) Init

func (m *Mock) Init()

func (*Mock) Validate

func (m *Mock) Validate() error

func (*Mock) Verify

func (m *Mock) Verify() bool

type MockContext

type MockContext struct {
	Times int `json:"times,omitempty" yaml:"times,omitempty"`
}

type MockProxy

type MockProxy struct {
	Host           string         `json:"host" yaml:"host"`
	Delay          Delay          `json:"delay,omitempty" yaml:"delay,omitempty"`
	FollowRedirect bool           `json:"follow_redirect,omitempty" yaml:"follow_redirect,omitempty"`
	SkipVerifyTLS  bool           `json:"skip_verify_tls,omitempty" yaml:"skip_verify_tls,omitempty"`
	KeepHost       bool           `json:"keep_host,omitempty" yaml:"keep_host,omitempty"`
	Headers        MapStringSlice `json:"headers,omitempty" yaml:"headers,omitempty"`
}

func (MockProxy) Redirect

func (mp MockProxy) Redirect(req Request) (*MockResponse, error)

type MockRequest

type MockRequest struct {
	Path        StringMatcher   `json:"path" yaml:"path"`
	Method      StringMatcher   `json:"method" yaml:"method"`
	Body        *BodyMatcher    `json:"body,omitempty" yaml:"body,omitempty"`
	QueryParams MultiMapMatcher `json:"query_params,omitempty" yaml:"query_params,omitempty"`
	Headers     MultiMapMatcher `json:"headers,omitempty" yaml:"headers,omitempty"`
}

func (MockRequest) Match

func (mr MockRequest) Match(req Request) bool

type MockResponse

type MockResponse struct {
	Body    string         `json:"body,omitempty" yaml:"body,omitempty"`
	Status  int            `json:"status" yaml:"status"`
	Delay   Delay          `json:"delay,omitempty" yaml:"delay,omitempty"`
	Headers MapStringSlice `json:"headers,omitempty" yaml:"headers,omitempty"`
}

type MockState

type MockState struct {
	ID           string    `json:"id" yaml:"id"`
	TimesCount   int       `json:"times_count" yaml:"times_count"`
	Locked       bool      `json:"locked" yaml:"locked"`
	CreationDate time.Time `json:"creation_date" yaml:"creation_date"`
}

type Mocks

type Mocks []*Mock

func (Mocks) Clone

func (m Mocks) Clone() Mocks

type MultiMapMatcher

type MultiMapMatcher map[string]StringMatcherSlice

func (MultiMapMatcher) Match

func (mmm MultiMapMatcher) Match(values map[string][]string) bool

type Request

type Request struct {
	Path        string      `json:"path"`
	Method      string      `json:"method"`
	Origin      string      `json:"origin"`
	BodyString  string      `json:"body_string" yaml:"body_string"`
	Body        interface{} `json:"body,omitempty" yaml:"body,omitempty"`
	QueryParams url.Values  `json:"query_params,omitempty" yaml:"query_params,omitempty"`
	Headers     http.Header `json:"headers,omitempty" yaml:"headers,omitempty"`
	Date        time.Time   `json:"date" yaml:"date"`
}

func HTTPRequestToRequest

func HTTPRequestToRequest(req *http.Request) Request

type Response

type Response struct {
	Status  int         `json:"status"`
	Body    interface{} `json:"body,omitempty" yaml:"body,omitempty"`
	Headers http.Header `json:"headers,omitempty" yaml:"headers,omitempty"`
	Date    time.Time   `json:"date" yaml:"date"`
}

type Session

type Session struct {
	ID      string    `json:"id"`
	Name    string    `json:"name"`
	Date    time.Time `json:"date"`
	History History   `json:"history"`
	Mocks   Mocks     `json:"mocks"`
}

func (*Session) Clone

func (s *Session) Clone() *Session

func (Session) Summarize

func (s Session) Summarize() SessionSummary

type SessionSummary

type SessionSummary struct {
	ID      string    `json:"id"`
	Name    string    `json:"name"`
	Date    time.Time `json:"date"`
	History History   `json:"-" yaml:"-"`
	Mocks   Mocks     `json:"-" yaml:"-"`
}

type Sessions

type Sessions []*Session

func (Sessions) Clone

func (s Sessions) Clone() Sessions

func (Sessions) Summarize

func (s Sessions) Summarize() []SessionSummary

type StringMatcher

type StringMatcher struct {
	Matcher string `json:"matcher" yaml:"matcher,flow"`
	Value   string `json:"value" yaml:"value,flow"`
}

func (StringMatcher) Match

func (sm StringMatcher) Match(value string) bool

func (*StringMatcher) UnmarshalJSON

func (sm *StringMatcher) UnmarshalJSON(data []byte) error

func (*StringMatcher) UnmarshalYAML

func (sm *StringMatcher) UnmarshalYAML(unmarshal func(interface{}) error) error

func (StringMatcher) Validate

func (sm StringMatcher) Validate() error

type StringMatcherSlice

type StringMatcherSlice []StringMatcher

func (StringMatcherSlice) Match

func (sms StringMatcherSlice) Match(values []string) bool

func (*StringMatcherSlice) UnmarshalJSON

func (sms *StringMatcherSlice) UnmarshalJSON(data []byte) error

func (*StringMatcherSlice) UnmarshalYAML

func (sms *StringMatcherSlice) UnmarshalYAML(unmarshal func(interface{}) error) error

type StringSlice

type StringSlice []string

StringSlice is a type that can unmarshal a string as a slice string This allows to write a single item slice as a string

func (*StringSlice) UnmarshalJSON

func (ss *StringSlice) UnmarshalJSON(data []byte) error

func (*StringSlice) UnmarshalYAML

func (ss *StringSlice) UnmarshalYAML(unmarshal func(interface{}) error) error

type VerifyResult

type VerifyResult struct {
	Mocks struct {
		Verified bool   `json:"verified"`
		AllUsed  bool   `json:"all_used"`
		Message  string `json:"message"`
		Failures Mocks  `json:"failures,omitempty"`
		Unused   Mocks  `json:"unused,omitempty"`
	} `json:"mocks"`
	History struct {
		Verified bool    `json:"verified"`
		Message  string  `json:"message"`
		Failures History `json:"failures,omitempty"`
	} `json:"history"`
}

Jump to

Keyboard shortcuts

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