scene

package
v0.0.0-...-785f0e5 Latest Latest
Warning

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

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

Documentation

Overview

Package scene include test file(yaml) and how to parse yaml

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Assert

func Assert(check []*Check, params map[string][]byte) error

func From

func From(source *entity.HTTPResponse, from FromType) any

func GetUuid

func GetUuid(prefix string) string

func Load

func Load(data []byte, scene *Scene) error

Load load scene data

func LoadJSONFile

func LoadJSONFile(file string, scene *Scene) error

func LoadYamlFile

func LoadYamlFile(file string, scene *Scene) error

func Render

func Render(origin string, variables map[string]any) (string, error)

Render render template's variables, like jinja2

func ToBytes

func ToBytes(str string) []byte

func ToString

func ToString(bs []byte) string

Types

type Assertion

type Assertion string
const (
	Equal    Assertion = "equal"
	NotEqual Assertion = "not_equal"
	Contain  Assertion = "contain"
)

type Check

type Check struct {
	Name       string    `json:"name" yaml:"name"`
	AssertType Assertion `json:"assert_type" yaml:"assert_type"`
	Expected   string    `json:"expected" yaml:"expected"`
	Actually   string    `json:"actually" yaml:"actually"`
	ErrorMsg   string    `json:"error_msg" yaml:"error_msg"`
	Disabled   bool      `json:"disabled" yaml:"disabled"`
}

Check assert for the step

type ExtractType

type ExtractType string
const (
	JSONPath ExtractType = "JSONPath"
	Regex    ExtractType = "Regex"
)

type Extractor

type Extractor interface {
	Extract(source *entity.HTTPResponse) ([]byte, error)
}

func NewExtractor

func NewExtractor(out *Out) Extractor

func NewJSONPathExtractor

func NewJSONPathExtractor(out *Out) Extractor

type FromType

type FromType string
const (
	Response       FromType = "Response"
	RequestHeader  FromType = "RequestHeader"
	ResponseHeader FromType = "ResponseHeader"
	StatusCode     FromType = "StatusCode"
)

type JSONPathExtractor

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

func (*JSONPathExtractor) Extract

func (j *JSONPathExtractor) Extract(source *entity.HTTPResponse) (s []byte, err error)

type Out

type Out struct {
	Name string `json:"name" yaml:"name"`
	// parameters from
	From        FromType    `json:"from" yaml:"from"`
	ExtractType ExtractType `json:"extractType" yaml:"extract_type"`
	Expression  string      `json:"expression" yaml:"expression"`
	Variable    string      `json:"variable" yaml:"variable"`
}

Out extract parameters

type RegexExtractor

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

type Scene

type Scene struct {
	Name  string  `json:"name" yaml:"name"`
	Steps []*Step `json:"steps" yaml:"steps"`
}

Scene a testing scene

type Step

type Step struct {
	Name        string            `yaml:"name" json:"name"`
	Url         string            `yaml:"url" json:"url"`
	Headers     map[string]string `json:"headers" yaml:"headers"`
	Method      string            `yaml:"method" json:"method"`
	Body        string            `json:"body" yaml:"body"`
	StatusCheck bool              `json:"status_check" yaml:"status_check"`
	Out         []*Out            `json:"out" yaml:"out"`
	Check       []*Check          `json:"check" yaml:"check"`
	Query       map[string]string `json:"query" yaml:"query"`
	Timeout     int               `json:"timeout"`
}

Step test step

Jump to

Keyboard shortcuts

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