apitestsv2

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Aug 15, 2024 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Overview

* v1_jsonbody 兼容 apitestsv1 里的 json body 渲染逻辑: - 反序列化,当类型是 map 或 slice 时进行处理 - value(map 的 value、slice 的 value) 必须**全量匹配** {{.+}},不支持 {{.+}}xxx 这种 - 匹配之后,替换时根据配置的具体类型进行渲染

举例: - 例如 map 有一组 kv 为 "key1": "{{ticketID}}"

  • 若参数 ticketID 为 integer(10),渲染结果为 "key1": 10
  • 若参数 ticketID 为 string("10"),渲染结果为 "key1": "10"

- 假如 map 有一组 kv 为 "key1": {{ticketID}}

  • 此时反序列化失败,不进行 v1 渲染
  • 此时走 v2 渲染逻辑,即文本渲染。若参数为 ticketID=10
  • "key1": {{ticketID}} => "key1": 10
  • "key1": "{{ticketID}}" => "key1": "10"
  • "key1": "{{ticketID}}-xxx" => "key1": "10-xxx"
  • "key1": {{ticketID}}-xxx => "key1": 10-xxx

Index

Constants

View Source
const HeaderCookie = "Cookie"
View Source
const HeaderSetCookie = "Set-Cookie"

Variables

This section is empty.

Functions

This section is empty.

Types

type APIParam

type APIParam struct {
	Key   string      `json:"key"`
	Value interface{} `json:"value"`
	Desc  string      `json:"desc"`
}

type APITest

type APITest struct {
	// dice api test 声明,包括入参、出参、断言等
	API *apistructs.APIInfo

	// 运行时结果,包括 response、断言结果、接口测试结果等
	APIResult *apistructs.ApiTestInfo
	// contains filtered or unexported fields
}

APITest API 测试的结构信息

func New

func New(api *apistructs.APIInfo, opOptions ...OpOption) *APITest

func (*APITest) Invoke

func (at *APITest) Invoke(httpClient *http.Client, testEnv *apistructs.APITestEnvData, caseParams map[string]*apistructs.CaseParams) (
	*apistructs.APIRequestInfo, *apistructs.APIResp, error)

Invoke 执行 API 测试

func (*APITest) JudgeAsserts

func (at *APITest) JudgeAsserts(outParams map[string]interface{}, asserts []apistructs.APIAssert) (bool, []*apistructs.APITestsAssertData)

JudgeAsserts 执行断言测试

func (*APITest) ParseOutParams

func (at *APITest) ParseOutParams(apiOutParams []apistructs.APIOutParam, apiResp *apistructs.APIResp,
	caseParams map[string]*apistructs.CaseParams) map[string]interface{}

ParseOutParams 解析 API 执行结果的出参,存储为全局变量,供后续使用

type OpOption

type OpOption func(*option)

func WithNetportalConfigs

func WithNetportalConfigs(netportalURL string) OpOption

WithNetportalConfigs set netportal url, whitelist and others.

func WithTryV1RenderJsonBodyFirst

func WithTryV1RenderJsonBodyFirst() OpOption

WithTryV1RenderJsonBodyFirst 尝试先使用 v1 严格模式渲染 json body。不论是否打开开关,都会再使用 v2 逻辑渲染一遍。 为手动测试的接口测试提供兼容处理;自动化测试无需打开该开关。

Directories

Path Synopsis
Package cookiejar implements an in-memory RFC 6265-compliant http.CookieJar.
Package cookiejar implements an in-memory RFC 6265-compliant http.CookieJar.

Jump to

Keyboard shortcuts

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