config

package
v1.0.9 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2023 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const ConfigType = "yaml"
View Source
const TplBrace = "{{"

Variables

This section is empty.

Functions

func ReadFromFile

func ReadFromFile(path string) (v *viper.Viper, err error)

func ReadLines

func ReadLines(path string) (lines map[int]map[int]string, err error)

ReadLines read the file content, and return the lines NOTE: we trans all line to lower case should get more info, mut

Types

type Assert

type Assert struct {
	Status      string   `yaml:"status"`
	StatusIn    []string `yaml:"status_in" mapstructure:"status_in"`
	StatusNotIn []string `yaml:"status_not_in" mapstructure:"status_not_in"`

	StatusCode      int   `yaml:"statusCode"`
	StatusCodeIn    []int `yaml:"statusCode_in" mapstructure:"statusCode_in"`
	StatusCodeNotIn []int `yaml:"statusCode_not_in" mapstructure:"statusCode_not_in"`
	StatusCodeLt    int   `yaml:"statusCode_lt" mapstructure:"statusCode_lt"`
	StatusCodeLte   int   `yaml:"statusCode_lte" mapstructure:"statusCode_lte"`
	StatusCodeGt    int   `yaml:"statusCode_gt" mapstructure:"statusCode_gt"`
	StatusCodeGte   int   `yaml:"statusCode_gte" mapstructure:"statusCode_gte"`

	ContentLength    int64 `yaml:"contentLength"`
	ContentLengthLt  int64 `yaml:"contentLength_lt" mapstructure:"contentLength_lt"`
	ContentLengthLte int64 `yaml:"contentLength_lte" mapstructure:"contentLength_lte"`
	ContentLengthGt  int64 `yaml:"contentLength_gt" mapstructure:"contentLength_gt"`
	ContentLengthGte int64 `yaml:"contentLength_gte" mapstructure:"contentLength_gte"`

	ContentType      string   `yaml:"contentType"`
	ContentTypeIn    []string `yaml:"contentType_in" mapstructure:"contentType_in"`
	ContentTypeNotIn []string `yaml:"contentType_not_in" mapstructure:"contentType_not_in"`

	// latency
	LatencyLt  int64 `yaml:"latency_lt" mapstructure:"latency_lt"`
	LatencyLte int64 `yaml:"latency_lte" mapstructure:"latency_lte"`
	LatencyGt  int64 `yaml:"latency_gt" mapstructure:"latency_gt"`
	LatencyGte int64 `yaml:"latency_gte" mapstructure:"latency_gte"`

	Body string `yaml:"body"`

	BodyContains      []string `yaml:"body_contains" mapstructure:"body_contains"`
	BodyNotContains   []string `yaml:"body_not_contains" mapstructure:"body_not_contains"`
	BodyIContains     []string `yaml:"body_icontains" mapstructure:"body_icontains"`
	BodyStartsWith    string   `yaml:"body_startswith" mapstructure:"body_startswith"`
	BodyEndsWith      string   `yaml:"body_endswith" mapstructure:"body_endswith"`
	BodyNotStartsWith string   `yaml:"body_not_startswith" mapstructure:"body_not_startswith"`
	BodyNotEndsWith   string   `yaml:"body_not_endswith" mapstructure:"body_not_endswith"`
	BodyMatches       string   `yaml:"body_matches" mapstructure:"body_matches"`
	BodyNotMatches    string   `yaml:"body_not_matches" mapstructure:"body_not_matches"`

	Header              map[string]interface{} `yaml:"header"`
	HeaderExists        []string               `yaml:"header_exists" mapstructure:"header_exists"`
	HeaderValueMatches  map[string]string      `yaml:"header_value_matches" mapstructure:"header_value_matches"`
	HeaderValueContains map[string]string      `yaml:"header_value_contains" mapstructure:"header_value_contains"`

	JSON []AssertJSON `yaml:"json" mapstructure:"json"`
	XML  []AssertXML  `yaml:"xml" mapstructure:"xml"`
	HTML []AssertHTML `yaml:"html" mapstructure:"html"`
	YAML []AssertYAML `yaml:"yaml" mapstructure:"yaml"`
	TOML []AssertTOML `yaml:"toml" mapstructure:"toml"`

	Cookie       []AssertCookie `yaml:"cookie" mapstructure:"cookie"`
	CookieExists []string       `yaml:"cookie_exists" mapstructure:"cookie_exists"`

	// if request fail like dial fail/context deadline exceeded, will do assert error_contains only,
	// will pass if the error message contains the string
	ErrorContains []string `yaml:"error_contains" mapstructure:"error_contains"`

	HasRedirect      bool  `yaml:"has_redirect" mapstructure:"has_redirect"`
	RedirectCountLt  int64 `yaml:"redirectCount_lt" mapstructure:"redirectCount_lt"`
	RedirectCountLte int64 `yaml:"redirectCount_lte" mapstructure:"redirectCount_lte"`
	RedirectCountGt  int64 `yaml:"redirectCount_gt" mapstructure:"redirectCount_gt"`
	RedirectCountGte int64 `yaml:"redirectCount_gte" mapstructure:"redirectCount_gte"`

	Proto      string `yaml:"proto"`      // e.g. "HTTP/1.0"
	ProtoMajor int    `yaml:"protoMajor"` // e.g. 1
	ProtoMinor int    `yaml:"protoMinor"` // e.g. 0

}

func (*Assert) Render

func (a *Assert) Render(ctx map[string]interface{})

type AssertCookie

type AssertCookie struct {
	// NOTE: https://go.dev/src/net/http/cookie_test.go
	// current only support check all equals(Name, Value, Domain, Path)
	Name   string
	Value  string
	Domain string
	Path   string
}

type AssertHTML

type AssertHTML struct {
	Path  string
	Value interface{}
}

type AssertJSON

type AssertJSON struct {
	Path  string
	Value interface{}
}

func (*AssertJSON) Render

func (a *AssertJSON) Render(ctx map[string]interface{})

type AssertTOML

type AssertTOML struct {
	Path  string
	Value interface{}
}

type AssertXML

type AssertXML struct {
	Path  string
	Value interface{}
}

type AssertYAML

type AssertYAML struct {
	Path  string
	Value interface{}
}

type BasicAuth

type BasicAuth struct {
	Username string
	Password string
}

func (*BasicAuth) Empty

func (b *BasicAuth) Empty() bool

type Case

type Case struct {
	Title       string
	Description string
	Path        string
	Index       int

	Config CaseConfig `mapstructure:"config"`
	Env    map[string]interface{}

	Request Request
	Assert  Assert
	Hook    Hook

	Parse []Parse

	// caseIndex => {lineNo: lineContent}
	FileLines map[int]map[int]string
	AllKeys   []string
}

func ReadCasesFromFile

func ReadCasesFromFile(path string) (cases []*Case, err error)

func (*Case) GuessAssertLineNumber

func (c *Case) GuessAssertLineNumber(caseIndex int, key string) int

GetAssertLineNumber will guess the assertion line number toml: status = "ok" json: "status": "ok" yaml: status: ok ini: status=ok

func (*Case) ID

func (c *Case) ID() string

func (*Case) Render

func (c *Case) Render(ctx map[string]interface{})

type CaseConfig

type CaseConfig struct {
	// timeout in ms
	Timeout int

	Retry Retry

	Repeat int
}

type Hook

type Hook struct {
	SaveCookie   string `mapstructure:"save_cookie"`
	SaveResponse string `mapstructure:"save_response"`
	Exec         string `mapstructure:"exec"`
	Sleep        int    `mapstructure:"sleep"`
}

TODO: use reflect instead hard code

type Order

type Order struct {
	Pattern string
	// TODO: not supported yet
	Parallel bool
}

type Parse

type Parse struct {
	Key    string `yaml:"key" mapstructure:"key"`
	Source string `yaml:"source" mapstructure:"source"`
	// body: json
	Jmespath string `yaml:"jmespath" mapstructure:"jmespath"`
	// header name
	Header string `yaml:"header" mapstructure:"header"`
}

type Request

type Request struct {
	Method string
	URL    string
	Body   string

	Header          map[string]string
	Cookie          string
	BasicAuth       BasicAuth `mapstructure:"basic_auth"`
	DisableRedirect bool      `mapstructure:"disable_redirect"`
	MaxRedirects    int       `mapstructure:"max_redirects"`
}

func (*Request) Render

func (r *Request) Render(ctx map[string]interface{})

type Retry

type Retry struct {
	Enable bool
	// retry times
	Count int
	// in ms
	Interval int
	// match the status_codes will do retry
	StatusCodes []int
	BodyMatches string
}

type RunConfig

type RunConfig struct {
	Debug bool
	Env   map[string]interface{}

	// exit 1 if got one assert fail
	FailFast bool

	// timeout in ms
	Timeout int

	Order []Order
}

Jump to

Keyboard shortcuts

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