wiregock

package module
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2024 License: GPL-3.0 Imports: 18 Imported by: 1

README

wiregock

Small and very fast and stable implementation of Wiremock with Goland and MongoDB based of fiber lib.

Request Matching

Stub matching and verification queries can use the following request attributes:

  • URL
  • HTTP Method
  • Query parameters
  • Form parameters
  • Headers
  • Basic authentication (a special case of header matching)
  • Cookies
  • Request body
  • Traceparent
HTTP methods
  • ANY all methods are accepted
  • GET
  • HEAD
  • OPTIONS
  • TRACE
  • PUT
  • DELETE
  • POST
  • PATCH
  • CONNECT
Request mapping
  • urlPath, url equality matching on path and query
  • urlPattern regex matching on path and query
  • method HTTP method. To accept all, use ANY
  • headers
  • queryParameters
  • cookies
  • bodyPatterns
  • basicAuthCredentials
  • matchingType accept only ALL (default) params or ANY of params
Comparation
  • equalTo exact equality
  • binaryEqualTo Unlike the above equalTo operator, this compares byte arrays (or their equivalent base64 representation).
  • contains string contains the value
  • matches compare by RegExp
  • wildcards compare with wildcards (*, ?)
  • equalToJson if the attribute (most likely the request body in practice) is valid JSON and is a semantic match for the expected value.
  • equalToXml if the attribute value is valid XML and is semantically equal to the expected XML document
  • matchesXPath XPath matcher for XML objects.
Templates

Templates are based on mustache engine. There's support of default variable request based on request data.

  • request.id - The unique ID of each request
  • request.url - URL path and query
  • #request.queryFull. - values of a query parameter (zero indexed) e.g. {{#request.queryFull.search}}{{.}}{{/request.queryFull.search}}
  • request.query. - First value of a query parameter e.g. request.query.search
  • request.method - request method e.g. POST
  • request.host - hostname part of the URL e.g. my.example.com
  • request.port - port number e.g. 8080
  • request.scheme - protocol part of the URL e.g. https
  • request.baseUrl - URL up to the start of the path e.g. https://my.example.com:8080
  • #request.headersFull. - values of a header (zero indexed) e.g. {{#request.headers.ManyThings}}{{.}}{{/request.headers.ManyThings}}
  • request.headers. - first value of a request header e.g. request.headers.X-Request-Id
  • request.cookies. - First value of a request cookie e.g. request.cookies.JSESSIONID
  • request.body - Request body text (avoid for non-text bodies)
  • request.bodyAsBase64 - The Base64 representation of the request body.

To Be Implemented

Comparation
  • matchesJsonPath JSON matcher
  • matchesJsonSchema JSON schema matcher
Templates
  • xmlPath and jsonPath helpers
  • request.parts template for multipart files

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CookiesToMap added in v1.2.0

func CookiesToMap(cookies []*http.Cookie) map[string]string

func GenerateTraceparent added in v0.6.6

func GenerateTraceparent() string

func LoadMethods added in v0.6.8

func LoadMethods(methodNames string) []string

func ParseQuery added in v1.2.0

func ParseQuery(values url.Values) map[string]map[string]string

func StringWithCharset

func StringWithCharset(length int, charset string) string

func ToSingleValueMap added in v1.2.0

func ToSingleValueMap(values map[string][]string) map[string]string

Types

type AbsentRule

type AbsentRule struct {
}

type AndCondition

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

func (AndCondition) Check added in v0.6.8

func (c AndCondition) Check() (bool, error)

type BlockRule added in v1.0.0

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

type Condition

type Condition interface {
	Check() (bool, error)
}

type ContainsRule

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

type DataCondition

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

func (DataCondition) Check added in v0.6.8

func (c DataCondition) Check() (bool, error)

type DataContext

type DataContext struct {
	Body          func() string
	Get           func(key string) string
	GetMulti      func(key string) []string
	Params        func(key string) string
	ParamsMulti   func(key string) []string
	Cookies       func(key string) string
	FormValue     func(key string) string
	MultipartForm func() []FileFormData
}

type DateTimeRule

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

type EqualToBaseRule added in v1.0.0

type EqualToBaseRule struct {
	IgnoreArrayOrder    bool
	IgnoreExtraElements bool
}

type EqualToBinaryRule

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

type EqualToJsonRule

type EqualToJsonRule struct {
	EqualToBaseRule
	// contains filtered or unexported fields
}

type EqualToRule

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

type EqualToXmlRule

type EqualToXmlRule struct {
	EqualToBaseRule
	// contains filtered or unexported fields
}

type FalseRule

type FalseRule struct {
}

type FileDataCondition added in v1.0.0

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

func (FileDataCondition) Check added in v1.0.0

func (c FileDataCondition) Check() (bool, error)

type FileFormData added in v1.0.0

type FileFormData struct {
	FileName string
	Headers  map[string][]string
	Data     string
}

type Filter

type Filter struct {
	Contains            *string    `json:"contains,omitempty" bson:"contains,omitempty"`
	EqualTo             *string    `json:"equalTo,omitempty" bson:"equalTo,omitempty"`
	CaseInsensitive     *bool      `json:"caseInsensitive,omitempty" bson:"caseInsensitive,omitempty"`
	BinaryEqualTo       *string    `json:"binaryEqualTo,omitempty" bson:"binaryEqualTo,omitempty"`
	DoesNotContain      *string    `json:"doesNotContain,omitempty" bson:"doesNotContain,omitempty"`
	Matches             *string    `json:"matches,omitempty" bson:"matches,omitempty"`
	DoesNotMatch        *string    `json:"doesNotMatch,omitempty" bson:"doesNotMatch,omitempty"`
	Absent              *bool      `json:"absent,omitempty" bson:"absent,omitempty"`
	And                 []Filter   `json:"and,omitempty" bson:"and,omitempty"`
	Or                  []Filter   `json:"or,omitempty" bson:"or,omitempty"`
	Before              *time.Time `json:"before,omitempty" bson:"before,omitempty"` // "2021-05-01T00:00:00Z"
	After               *time.Time `json:"after,omitempty" bson:"after,omitempty"`   // "2021-05-01T00:00:00Z"
	EqualToDateTime     *time.Time `json:"equalToDateTime,omitempty" bson:"equalToDateTime,omitempty"`
	ActualFormat        *string    `json:"actualFormat,omitempty" bson:"actualFormat,omitempty"`
	EqualToJson         *string    `json:"equalToJson,omitempty" bson:"equalToJson,omitempty"`
	IgnoreArrayOrder    *bool      `json:"ignoreArrayOrder,omitempty" bson:"ignoreArrayOrder,omitempty"`
	IgnoreExtraElements *bool      `json:"ignoreExtraElements,omitempty" bson:"ignoreExtraElements,omitempty"`
	//  TODO - implement with https://pkg.go.dev/github.com/PaesslerAG/jsonpath
	//	MatchesJsonPath     *XPathFilter  `json:"matchesJsonPath,omitempty" bson:"matchesJsonPath,omitempty"`
	EqualToXml   *string       `json:"equalToXml,omitempty" bson:"equalToXml,omitempty"`
	MatchesXPath *XPathFilter  `json:"matchesXPath,omitempty" bson:"matchesXPath,omitempty"`
	Includes     []MultiFilter `json:"includes,omitempty" bson:"includes,omitempty"`
	HasExactly   []MultiFilter `json:"hasExactly,omitempty" bson:"hasExactly,omitempty"`
}

type MatchesBaseXPathRule added in v1.0.0

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

type MatchesJsonXPathRule added in v1.0.0

type MatchesJsonXPathRule struct {
	MatchesBaseXPathRule
}

type MatchesXmlXPathRule added in v1.0.0

type MatchesXmlXPathRule struct {
	MatchesBaseXPathRule
}

type MockData

type MockData struct {
	Request  *MockRequest `json:"request" bson:"request"`
	Response *struct {
		Status       *int              `json:"status,omitempty" bson:"status,omitempty"`
		Body         *string           `json:"body,omitempty" bson:"body,omitempty"`
		BodyFileName *string           `json:"bodyFileName,omitempty" bson:"bodyFileName,omitempty"`
		JsonBody     *interface{}      `json:"jsonBody,omitempty" bson:"jsonBody,omitempty"`
		Headers      map[string]string `json:"headers,omitempty" bson:"headers,omitempty"`
		Cookies      map[string]string `json:"cookies,omitempty" bson:"cookies,omitempty"`
	} `json:"response" bson:"response"`
	Vars *map[string]string `json:"vars,omitempty" bson:"vars,omitempty"`
}

type MockRequest

type MockRequest struct {
	UrlPath              *string                 `json:"urlPath,omitempty" bson:"urlPath,omitempty"`
	UrlPattern           *string                 `json:"urlPattern,omitempty" bson:"urlPattern,omitempty"`
	Method               *string                 `json:"method,omitempty" bson:"method,omitempty"`
	Headers              map[string]Filter       `json:"headers,omitempty" bson:"headers,omitempty"`
	QueryParameters      map[string]Filter       `json:"queryParameters,omitempty" bson:"queryParameters,omitempty"`
	FormParameters       map[string]Filter       `json:"formParameters,omitempty" bson:"formParameters,omitempty"`
	Cookies              map[string]Filter       `json:"cookies,omitempty" bson:"cookies,omitempty"`
	BodyPatterns         []Filter                `json:"bodyPatterns,omitempty" bson:"bodyPatterns,omitempty"`
	MultipartPatterns    []MultipartPatternsData `json:"multipartPatterns,omitempty" bson:"multipartPatterns,omitempty"`
	BasicAuthCredentials *struct {
		Username *string `json:"username,omitempty" bson:"username,omitempty"`
		Password *string `json:"password,omitempty" bson:"password,omitempty"`
	} `json:"basicAuthCredentials,omitempty" bson:"basicAuthCredentials,omitempty"`
}

type MultiDataCondition added in v1.0.0

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

func (MultiDataCondition) Check added in v1.0.0

func (c MultiDataCondition) Check() (bool, error)

type MultiFilter added in v1.0.0

type MultiFilter struct {
	EqualTo         *string `json:"equalTo,omitempty" bson:"equalTo,omitempty"`
	Contains        *string `json:"contains,omitempty" bson:"contains,omitempty"`
	DoesNotContain  *string `json:"doesNotContain,omitempty" bson:"doesNotContain,omitempty"`
	CaseInsensitive *bool   `json:"caseInsensitive,omitempty" bson:"caseInsensitive,omitempty"`
}

type MultipartPatternsData added in v1.0.0

type MultipartPatternsData struct {
	MatchingType *string           `json:"matchingType,omitempty" bson:"matchingType,omitempty"`
	FileName     *Filter           `json:"fileName,omitempty" bson:"fileName,omitempty"`
	Headers      map[string]Filter `json:"headers,omitempty" bson:"headers,omitempty"`
	BodyPatterns []Filter          `json:"bodyPatterns,omitempty" bson:"bodyPatterns,omitempty"`
}

type NotRule

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

type OrCondition

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

func (OrCondition) Check added in v0.6.8

func (c OrCondition) Check() (bool, error)

type ParsedConditions added in v1.0.0

type ParsedConditions struct {
	IsMultipart bool
	Condition   Condition
}

func ParseCondition added in v0.6.6

func ParseCondition(request *MockRequest, context *DataContext) (*ParsedConditions, error)

type ParsedRules added in v1.0.0

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

type RegExRule

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

type RequestData added in v1.2.0

type RequestData map[string]interface{}

func LoadRequestData added in v1.2.0

func LoadRequestData(req *http.Request) (*RequestData, error)

type Rule

type Rule interface {
	// contains filtered or unexported methods
}

type TrueRule

type TrueRule struct {
}

type WildcardsRule

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

type XPathFactory added in v1.0.0

type XPathFactory interface {
	// contains filtered or unexported methods
}

type XPathFilter added in v0.6.2

type XPathFilter struct {
	Expression          string            `json:"-" bson:"-"`
	EqualTo             *string           `json:"equalTo,omitempty" bson:"equalTo,omitempty"`
	EqualToJson         *string           `json:"equalToJson,omitempty" bson:"equalToJson,omitempty"`
	EqualToXml          *string           `json:"equalToXml,omitempty" bson:"equalToXml,omitempty"`
	Contains            *string           `json:"contains,omitempty" bson:"contains,omitempty"`
	CaseInsensitive     *bool             `json:"caseInsensitive,omitempty" bson:"caseInsensitive,omitempty"`
	IgnoreArrayOrder    *bool             `json:"ignoreArrayOrder,omitempty" bson:"ignoreArrayOrder,omitempty"`
	IgnoreExtraElements *bool             `json:"ignoreExtraElements,omitempty" bson:"ignoreExtraElements,omitempty"`
	And                 []XPathFilter     `json:"and,omitempty" bson:"and,omitempty"`
	Before              *time.Time        `json:"before,omitempty" bson:"before,omitempty"` // "2021-05-01T00:00:00Z"
	After               *time.Time        `json:"after,omitempty" bson:"after,omitempty"`   // "2021-05-01T00:00:00Z"
	EqualToDateTime     *time.Time        `json:"equalToDateTime,omitempty" bson:"equalToDateTime,omitempty"`
	ActualFormat        *string           `json:"actualFormat,omitempty" bson:"actualFormat,omitempty"`
	XPathNamespaces     map[string]string `json:"xPathNamespaces,omitempty" bson:"xPathNamespaces,omitempty"`
}

func (*XPathFilter) UnmarshalBSON added in v0.6.4

func (xPathFilter *XPathFilter) UnmarshalBSON(data []byte) error

func (*XPathFilter) UnmarshalJSON added in v0.6.2

func (xPathFilter *XPathFilter) UnmarshalJSON(data []byte) error

type XPathFilterProps added in v1.0.0

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

type XPathJsonFactory added in v1.0.0

type XPathJsonFactory struct{}

type XPathXmlFactory added in v1.0.0

type XPathXmlFactory struct{}

Jump to

Keyboard shortcuts

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