testing

package
v0.0.12 Latest Latest
Warning

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

Go to latest
Published: Jun 18, 2023 License: MIT Imports: 15 Imported by: 9

Documentation

Overview

Package testing provide the test case functions

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EmptyThenDefault added in v0.0.12

func EmptyThenDefault(val, defVal string) string

EmptyThenDefault return the default value if the val is empty

func ZeroThenDefault added in v0.0.12

func ZeroThenDefault(val, defVal int) int

ZeroThenDefault return the default value if the val is zero

Types

type Job added in v0.0.12

type Job struct {
	Items []string `yaml:"items"`
}

Job contains a list of jobs

type Loader added in v0.0.12

type Loader interface {
	HasMore() bool
	Load() ([]byte, error)
	Put(string) (err error)
	GetContext() string
	GetCount() int
}

Loader is an interface for test cases loader

func NewFileLoader added in v0.0.12

func NewFileLoader() Loader

NewFileLoader creates the instance of file loader

type Request

type Request struct {
	API          string            `yaml:"api" json:"api"`
	Method       string            `yaml:"method,omitempty" json:"method,omitempty" jsonschema:"enum=GET,enum=POST,enum=PUT,enum=DELETE"`
	Query        map[string]string `yaml:"query,omitempty" json:"query,omitempty"`
	Header       map[string]string `yaml:"header,omitempty" json:"header,omitempty"`
	Form         map[string]string `yaml:"form,omitempty" json:"form,omitempty"`
	Body         string            `yaml:"body,omitempty" json:"body,omitempty"`
	BodyFromFile string            `yaml:"bodyFromFile,omitempty" json:"bodyFromFile,omitempty"`
}

Request represents a HTTP request

func (*Request) GetBody added in v0.0.11

func (r *Request) GetBody() (reader io.Reader, err error)

GetBody returns the request body

func (*Request) Render added in v0.0.2

func (r *Request) Render(ctx interface{}, dataDir string) (err error)

Render injects the template based context

type Response

type Response struct {
	StatusCode       int                    `yaml:"statusCode,omitempty" json:"statusCode,omitempty"`
	Body             string                 `yaml:"body,omitempty" json:"body,omitempty"`
	Header           map[string]string      `yaml:"header,omitempty" json:"header,omitempty"`
	BodyFieldsExpect map[string]interface{} `yaml:"bodyFieldsExpect,omitempty" json:"bodyFieldsExpect,omitempty"`
	Verify           []string               `yaml:"verify,omitempty" json:"verify,omitempty"`
	Schema           string                 `yaml:"schema,omitempty" json:"schema,omitempty"`
}

Response is the expected response

func (*Response) Render added in v0.0.3

func (r *Response) Render(ctx interface{}) (err error)

Render renders the response

type TestCase

type TestCase struct {
	Name    string   `yaml:"name,omitempty" json:"name"`
	Group   string   `yaml:"group,omitempty" json:"group"`
	Before  Job      `yaml:"before,omitempty" json:"before"`
	After   Job      `yaml:"after,omitempty" json:"after"`
	Request Request  `yaml:"request" json:"request"`
	Expect  Response `yaml:"expect,omitempty" json:"expect"`
}

TestCase represents a test case

func ParseTestCaseFromData added in v0.0.5

func ParseTestCaseFromData(data []byte) (testCase *TestCase, err error)

ParseTestCaseFromData parses the data to a test case

func (*TestCase) InScope added in v0.0.11

func (c *TestCase) InScope(items []string) bool

InScope returns true if the test case is in scope with the given items. Returns true if the items is empty.

type TestSuite added in v0.0.2

type TestSuite struct {
	Name  string     `yaml:"name,omitempty" json:"name"`
	API   string     `yaml:"api,omitempty" json:"api,omitempty"`
	Items []TestCase `yaml:"items" json:"items"`
}

TestSuite represents a set of test cases

func Parse

func Parse(data []byte) (testSuite *TestSuite, err error)

Parse parses a file and returns the test suite

func ParseFromData added in v0.0.5

func ParseFromData(data []byte) (testSuite *TestSuite, err error)

ParseFromData parses data and returns the test suite

Jump to

Keyboard shortcuts

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