testing

package
v0.0.16 Latest Latest
Warning

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

Go to latest
Published: Apr 9, 2024 License: Apache-2.0 Imports: 20 Imported by: 9

Documentation

Overview

Copyright 2023 API Testing Authors.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Package testing provide the test case functions

Copyright 2023 API Testing Authors.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright 2023 API Testing Authors.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright 2023 API Testing Authors.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright 2023 API Testing Authors.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Index

Constants

View Source
const (
	ContextKeyGlobalParam = "param"
)

Variables

This section is empty.

Functions

func GetHeader added in v0.0.13

func GetHeader() string

GetHeader returns the header of the YAML config file

func SaveTestSuiteToFile added in v0.0.13

func SaveTestSuiteToFile(suite *TestSuite, suitePath string) (err error)

SaveTestSuiteToFile saves the test suite to file

func ToYAML added in v0.0.15

func ToYAML(suite *TestSuite) ([]byte, error)

Types

type APISpec added in v0.0.13

type APISpec struct {
	Kind   string   `yaml:"kind,omitempty" json:"kind,omitempty"`
	URL    string   `yaml:"url,omitempty" json:"url,omitempty"`
	RPC    *RPCDesc `yaml:"rpc,omitempty" json:"rpc,omitempty"`
	Secure *Secure  `yaml:"secure,omitempty" json:"secure,omitempty"`
}

type ConditionalVerify added in v0.0.14

type ConditionalVerify struct {
	Condition []string `yaml:"condition,omitempty" json:"condition,omitempty"`
	Verify    []string `yaml:"verify,omitempty" json:"verify,omitempty"`
}

type GraphQLRequestBody added in v0.0.16

type GraphQLRequestBody struct {
	Query         string            `yaml:"query" json:"query"`
	OperationName string            `yaml:"operationName" json:"operationName"`
	Variables     map[string]string `yaml:"variables" json:"variables"`
}

type Job added in v0.0.12

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

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
	Reset()

	Verify() (readOnly bool, err error)
	PProf(name string) []byte
}

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 RPCDesc added in v0.0.14

type RPCDesc struct {
	ImportPath       []string `yaml:"import,omitempty" json:"import,omitempty"`
	ServerReflection bool     `yaml:"serverReflection,omitempty" json:"serverReflection,omitempty"`
	ProtoFile        string   `yaml:"protofile,omitempty" json:"protofile,omitempty"`
	ProtoSet         string   `yaml:"protoset,omitempty" json:"protoset,omitempty"`
	Raw              string   `yaml:"raw,omitempty" json:"raw,omitempty"`
}

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        SortedKeysStringMap `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         RequestBody         `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

func (*Request) RenderAPI added in v0.0.13

func (r *Request) RenderAPI(base string)

RenderAPI will combine with the base API

type RequestBody added in v0.0.16

type RequestBody struct {
	Value string `json:"value" yaml:"value"`
	// contains filtered or unexported fields
}

func NewRequestBody added in v0.0.16

func NewRequestBody(val string) RequestBody

func (RequestBody) MarshalYAML added in v0.0.16

func (e RequestBody) MarshalYAML() (val interface{}, err error)

func (RequestBody) String added in v0.0.16

func (e RequestBody) String() string

func (*RequestBody) UnmarshalYAML added in v0.0.16

func (e *RequestBody) UnmarshalYAML(unmarshal func(interface{}) error) (err error)

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"`
	ConditionalVerify []ConditionalVerify    `yaml:"conditionalVerify,omitempty" json:"conditionalVerify,omitempty"`
	Schema            string                 `yaml:"schema,omitempty" json:"schema,omitempty"`
}

Response is the expected response

func (Response) GetBody added in v0.0.15

func (r Response) GetBody() string

func (Response) GetBodyFieldsExpect added in v0.0.15

func (r Response) GetBodyFieldsExpect() map[string]interface{}

func (*Response) Render added in v0.0.3

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

Render renders the response

type Secure added in v0.0.14

type Secure struct {
	Insecure   bool   `yaml:"insecure,omitempty" json:"insecure,omitempty"`
	CertFile   string `yaml:"cert,omitempty" json:"cert,omitempty"`
	CAFile     string `yaml:"ca,omitempty" json:"ca,omitempty"`
	KeyFile    string `yaml:"key,omitempty" json:"key,omitempty"`
	ServerName string `yaml:"serverName,omitempty" json:"serverName,omitempty"`
}

type SortedKeysStringMap added in v0.0.14

type SortedKeysStringMap map[string]interface{}

func (SortedKeysStringMap) GetValue added in v0.0.16

func (m SortedKeysStringMap) GetValue(key string) string

func (SortedKeysStringMap) GetVerifier added in v0.0.16

func (m SortedKeysStringMap) GetVerifier(key string) (verifier *Verifier)

func (SortedKeysStringMap) Keys added in v0.0.14

func (m SortedKeysStringMap) Keys() (keys []string)

type Store added in v0.0.13

type Store struct {
	Name        string
	Owner       string
	Kind        StoreKind
	Description string
	URL         string
	Username    string
	Password    string
	ReadOnly    bool
	Disabled    bool
	Properties  map[string]string
}

func MapToStore added in v0.0.13

func MapToStore(data map[string]string) (store Store)

func (*Store) ToMap added in v0.0.13

func (s *Store) ToMap() (result map[string]string)

type StoreConfig added in v0.0.14

type StoreConfig struct {
	Stores  []Store     `yaml:"stores"`
	Plugins []StoreKind `yaml:"plugins"`
}

type StoreGetterAndSetter added in v0.0.13

type StoreGetterAndSetter interface {
	GetStores() (stores []Store, err error)
	GetStoresByOwner(owner string) (stores []Store, err error)
	GetStore(name string) (store *Store, err error)
	DeleteStore(name string) (err error)
	UpdateStore(store Store) (err error)
	CreateStore(store Store) (err error)

	GetStoreKinds() (kinds []StoreKind, err error)
}

func NewStoreFactory added in v0.0.13

func NewStoreFactory(configDir string) StoreGetterAndSetter

NewStoreFactory creates a new store factory

type StoreKind added in v0.0.13

type StoreKind struct {
	Name    string
	URL     string
	Enabled bool
}

StoreKind represents a gRPC-based store

type StoreWriterFactory added in v0.0.13

type StoreWriterFactory interface {
	NewInstance(store Store) (writer Writer, err error)
}

type TestCase

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

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,omitempty"`
	API   string            `yaml:"api,omitempty" json:"api,omitempty"`
	Spec  APISpec           `yaml:"spec,omitempty" json:"spec,omitempty"`
	Param map[string]string `yaml:"param,omitempty" json:"param,omitempty"`
	Items []TestCase        `yaml:"items,omitempty" json:"items,omitempty"`
}

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

func ParseFromStream added in v0.0.13

func ParseFromStream(stream io.Reader) (testSuite *TestSuite, err error)

ParseFromStream parses the stream and returns the test suite

func ParseTestSuiteFromFile added in v0.0.13

func ParseTestSuiteFromFile(suitePath string) (testSuite *TestSuite, err error)

ParseTestSuiteFromFile parses from suite path

func (*TestSuite) Render added in v0.0.13

func (s *TestSuite) Render(dataContext map[string]interface{}) (err error)

Render injects the template based context

type Verifier added in v0.0.16

type Verifier struct {
	Value     string `yaml:"value,omitempty" json:"value,omitempty"`
	Required  bool   `yaml:"required,omitempty" json:"required,omitempty"`
	Max       int    `yaml:"max"`
	Min       int    `yaml:"min"`
	MaxLength int    `yaml:"maxLength"`
	MinLength int    `yaml:"minLength"`
}

type Writer added in v0.0.13

type Writer interface {
	Loader

	ListTestCase(suite string) (testcases []TestCase, err error)
	GetTestCase(suite, name string) (testcase TestCase, err error)
	CreateTestCase(suite string, testcase TestCase) (err error)
	UpdateTestCase(suite string, testcase TestCase) (err error)
	DeleteTestCase(suite, testcase string) (err error)

	ListTestSuite() (suites []TestSuite, err error)
	GetTestSuite(name string, full bool) (suite TestSuite, err error)
	CreateSuite(name, api string) (err error)
	GetSuite(name string) (*TestSuite, string, error)
	UpdateSuite(TestSuite) (err error)
	DeleteSuite(name string) (err error)
	Close()
}

func NewFileWriter added in v0.0.13

func NewFileWriter(parent string) Writer

func NewNonWriter added in v0.0.15

func NewNonWriter() Writer

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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