refactor: make models private

This commit is contained in:
debugtalk
2021-12-07 09:58:32 +08:00
parent 827f934d34
commit 5de87ac875
15 changed files with 115 additions and 113 deletions

View File

@@ -1,19 +1,17 @@
package hrp
type EnumHTTPMethod string
const (
GET EnumHTTPMethod = "GET"
HEAD EnumHTTPMethod = "HEAD"
POST EnumHTTPMethod = "POST"
PUT EnumHTTPMethod = "PUT"
DELETE EnumHTTPMethod = "DELETE"
OPTIONS EnumHTTPMethod = "OPTIONS"
PATCH EnumHTTPMethod = "PATCH"
httpGET string = "GET"
httpHEAD string = "HEAD"
httpPOST string = "POST"
httpPUT string = "PUT"
httpDELETE string = "DELETE"
httpOPTIONS string = "OPTIONS"
httpPATCH string = "PATCH"
)
type TConfig struct {
Name string `json:"name" yaml:"name"`
Name string `json:"name" yaml:"name"` // required
Verify bool `json:"verify,omitempty" yaml:"verify,omitempty"`
BaseURL string `json:"base_url,omitempty" yaml:"base_url,omitempty"`
Variables map[string]interface{} `json:"variables,omitempty" yaml:"variables,omitempty"`
@@ -22,9 +20,9 @@ type TConfig struct {
Weight int `json:"weight,omitempty" yaml:"weight,omitempty"`
}
type TRequest struct {
Method EnumHTTPMethod `json:"method" yaml:"method"`
URL string `json:"url" yaml:"url"`
type Request struct {
Method string `json:"method" yaml:"method"` // required
URL string `json:"url" yaml:"url"` // required
Params map[string]interface{} `json:"params,omitempty" yaml:"params,omitempty"`
Headers map[string]string `json:"headers,omitempty" yaml:"headers,omitempty"`
Cookies map[string]string `json:"cookies,omitempty" yaml:"cookies,omitempty"`
@@ -34,44 +32,48 @@ type TRequest struct {
Verify bool `json:"verify,omitempty" yaml:"verify,omitempty"`
}
type TValidator struct {
Check string `json:"check,omitempty" yaml:"check,omitempty"` // get value with jmespath
Assert string `json:"assert,omitempty" yaml:"assert,omitempty"`
Expect interface{} `json:"expect,omitempty" yaml:"expect,omitempty"`
Message string `json:"msg,omitempty" yaml:"msg,omitempty"`
type Validator struct {
Check string `json:"check" yaml:"check"` // get value with jmespath
Assert string `json:"assert" yaml:"assert"`
Expect interface{} `json:"expect" yaml:"expect"`
Message string `json:"msg,omitempty" yaml:"msg,omitempty"` // optional
}
// TStep represents teststep data structure.
// Each step maybe two different type: make one HTTP request or reference another testcase.
type TStep struct {
Name string `json:"name" yaml:"name"`
Transaction string `json:"transaction,omitempty" yaml:"transaction,omitempty"`
Request *TRequest `json:"request,omitempty" yaml:"request,omitempty"`
Name string `json:"name" yaml:"name"` // required
Request *Request `json:"request,omitempty" yaml:"request,omitempty"`
TestCase *TestCase `json:"testcase,omitempty" yaml:"testcase,omitempty"`
Variables map[string]interface{} `json:"variables,omitempty" yaml:"variables,omitempty"`
SetupHooks []string `json:"setup_hooks,omitempty" yaml:"setup_hooks,omitempty"`
TeardownHooks []string `json:"teardown_hooks,omitempty" yaml:"teardown_hooks,omitempty"`
Extract map[string]string `json:"extract,omitempty" yaml:"extract,omitempty"`
Validators []TValidator `json:"validate,omitempty" yaml:"validate,omitempty"`
Validators []Validator `json:"validate,omitempty" yaml:"validate,omitempty"`
Export []string `json:"export,omitempty" yaml:"export,omitempty"`
}
// used for testcase json loading and dumping
// TCase represents testcase data structure.
// Each testcase includes one public config and several sequential teststeps.
type TCase struct {
Config TConfig `json:"config" yaml:"config"`
TestSteps []*TStep `json:"teststeps" yaml:"teststeps"`
}
// interface for all types of steps
// IStep represents interface for all types for teststeps
type IStep interface {
Name() string
Type() string
ToStruct() *TStep
name() string
getType() string
toStruct() *TStep
}
// ITestCase represents interface for all types for testcases
type ITestCase interface {
ToTestCase() (*TestCase, error)
ToTCase() (*TCase, error)
}
// TestCase is a container for one testcase.
// used for testcase runner
type TestCase struct {
Config TConfig
@@ -86,11 +88,11 @@ type TestCasePath struct {
Path string
}
type TestCaseSummary struct{}
type testCaseSummary struct{}
type StepData struct {
Name string // step name
Success bool // step execution result
ResponseLength int64 // response body length
ExportVars map[string]interface{} // extract variables
type stepData struct {
name string // step name
success bool // step execution result
responseLength int64 // response body length
exportVars map[string]interface{} // extract variables
}