parsers

package
v1.19.4 Latest Latest
Warning

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

Go to latest
Published: Mar 27, 2024 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MatchFixtureQuery

func MatchFixtureQuery(value string) (*regexp.Regexp, bool)

MatchFixtureQuery will attempt to find matches for a fixture query pattern returning a *Regexp which can be used to further parse and a boolean indicating a match was found.

func ParseArray

func ParseArray(params []interface{}, parent string, queryRespMap map[string]gjson.Result) ([]string, error)

ParseArray is similar to parseMap but doesn't have to build the multi-depth keys. Form data arrays contain brackets with nothing inside the bracket to designate an array instead of a key value pair.

func ParseInterface

func ParseInterface(params interface{}, queryRespMap map[string]gjson.Result) ([]string, error)

ParseInterface is the primary entrypoint into building the request data for fixtures. The data will always be provided as an interface{} and this will need to use reflection to determine how to proceed. There are two primary paths here, `parseMap` and `ParseArray`, which will recursively traverse and convert the data

This returns an array of clean form data to make the request.

func ParseMap

func ParseMap(params map[string]interface{}, parent string, index int, queryRespMap map[string]gjson.Result) ([]string, error)

ParseMap recursively parses a map of string => interface{} until each leaf node has a terminal type (String, Int, etc) that can no longer be recursively traversed.

func ParsePath

func ParsePath(httpPath string, queryRespMap map[string]gjson.Result) (string, error)

ParsePath will inspect the path to see if it has a query in the path for requests that operate on specific objects (for example, GET /v1/customers/:id or POST /v1/subscriptions/:id)

If a query is found, this returns the path with the value already in place. If there is no query, it returns the old path as-is.

func ParseQuery

func ParseQuery(queryString string, queryRespMap map[string]gjson.Result) (string, error)

ParseQuery checks strings for possible queries and replaces the corresponding value in its place. The supported query format is:

$<name of fixture>:dot.path.to.field

Types

type FixtureQuery

type FixtureQuery struct {
	Match        string // The substring that matched the query pattern regex
	Name         string
	Query        string
	DefaultValue string
}

FixtureQuery describes the query in fixture request

func ToFixtureQuery

func ToFixtureQuery(value string) (FixtureQuery, bool)

ToFixtureQuery will parse a string into a fixtureQuery struct, additionally returning a bool indicating the value did contain a fixtureQuery.

Jump to

Keyboard shortcuts

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