From f0cedf274c009df166f33cbed523dd99c21e9acc Mon Sep 17 00:00:00 2001 From: debugtalk Date: Sat, 9 Oct 2021 14:50:52 +0800 Subject: [PATCH] feat: add TCase struct for json loading and dumping --- models.go | 63 ++++++++++++++++++++++++++++++------------------------- 1 file changed, 35 insertions(+), 28 deletions(-) diff --git a/models.go b/models.go index 9cc46949..c3716b5b 100644 --- a/models.go +++ b/models.go @@ -14,44 +14,50 @@ const ( type TConfig struct { Name string `json:"name"` - Verify bool `json:"verify"` - BaseURL string `json:"base_url"` - Variables map[string]interface{} `json:"variables"` - Parameters map[string]interface{} `json:"parameters"` - Export []string `json:"export"` - Weight int `json:"weight"` + Verify bool `json:"verify,omitempty"` + BaseURL string `json:"base_url,omitempty"` + Variables map[string]interface{} `json:"variables,omitempty"` + Parameters map[string]interface{} `json:"parameters,omitempty"` + Export []string `json:"export,omitempty"` + Weight int `json:"weight,omitempty"` } type TRequest struct { Method enumHTTPMethod `json:"method"` URL string `json:"url"` - Params map[string]interface{} `json:"params"` - Headers map[string]string `json:"headers"` - Cookies map[string]string `json:"cookies"` - Data interface{} `json:"data"` - JSON interface{} `json:"json"` - Timeout float32 `json:"timeout"` - AllowRedirects bool `json:"allow_redirects"` - Verify bool `json:"verify"` + Params map[string]interface{} `json:"params,omitempty"` + Headers map[string]string `json:"headers,omitempty"` + Cookies map[string]string `json:"cookies,omitempty"` + Data interface{} `json:"data,omitempty"` + JSON interface{} `json:"json,omitempty"` + Timeout float32 `json:"timeout,omitempty"` + AllowRedirects bool `json:"allow_redirects,omitempty"` + Verify bool `json:"verify,omitempty"` } type TValidator struct { - Check string // get value with jmespath - Assert string - Expect interface{} - Message string + Check string `json:"check,omitempty"` // get value with jmespath + Assert string `json:"assert,omitempty"` + Expect interface{} `json:"expect,omitempty"` + Message string `json:"msg,omitempty"` } type TStep struct { Name string `json:"name"` - Request *TRequest `json:"request"` - TestCase *TestCase `json:"testcase"` - Variables map[string]interface{} `json:"variables"` - SetupHooks []string `json:"setup_hooks"` - TeardownHooks []string `json:"teardown_hooks"` - Extract map[string]string `json:"extract"` - Validators []TValidator `json:"validators"` - Export []string `json:"export"` + Request *TRequest `json:"request,omitempty"` + TestCase *TestCase `json:"testcase,omitempty"` + Variables map[string]interface{} `json:"variables,omitempty"` + SetupHooks []string `json:"setup_hooks,omitempty"` + TeardownHooks []string `json:"teardown_hooks,omitempty"` + Extract map[string]string `json:"extract,omitempty"` + Validators []TValidator `json:"validate,omitempty"` + Export []string `json:"export,omitempty"` +} + +// used for testcase json loading and dumping +type TCase struct { + Config TConfig `json:"config"` + TestSteps []*TStep `json:"teststeps"` } // interface for all types of steps @@ -61,9 +67,10 @@ type IStep interface { ToStruct() *TStep } +// used for testcase runner type TestCase struct { - Config TConfig `json:"config"` - TestSteps []IStep `json:"teststeps"` + Config TConfig + TestSteps []IStep } type TestCaseSummary struct{}