mirror of
https://github.com/httprunner/httprunner.git
synced 2026-05-12 02:21:29 +08:00
refactor: use raw models
This commit is contained in:
57
models.go
57
models.go
@@ -1,10 +1,5 @@
|
||||
package httpboomer
|
||||
|
||||
type Variables map[string]interface{}
|
||||
type Params map[string]interface{}
|
||||
type Headers map[string]string
|
||||
type Cookies map[string]string
|
||||
|
||||
type enumHTTPMethod string
|
||||
|
||||
const (
|
||||
@@ -18,26 +13,26 @@ const (
|
||||
)
|
||||
|
||||
type TConfig struct {
|
||||
Name string `json:"name"`
|
||||
Verify bool `json:"verify"`
|
||||
BaseURL string `json:"base_url"`
|
||||
Variables Variables `json:"variables"`
|
||||
Parameters Variables `json:"parameters"`
|
||||
Export []string `json:"export"`
|
||||
Weight int `json:"weight"`
|
||||
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"`
|
||||
}
|
||||
|
||||
type TRequest struct {
|
||||
Method enumHTTPMethod `json:"method"`
|
||||
URL string `json:"url"`
|
||||
Params Params `json:"params"`
|
||||
Headers Headers `json:"headers"`
|
||||
Cookies Cookies `json:"cookies"`
|
||||
Data interface{} `json:"data"`
|
||||
JSON interface{} `json:"json"`
|
||||
Timeout float32 `json:"timeout"`
|
||||
AllowRedirects bool `json:"allow_redirects"`
|
||||
Verify bool `json:"verify"`
|
||||
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"`
|
||||
}
|
||||
|
||||
type TValidator struct {
|
||||
@@ -48,15 +43,15 @@ type TValidator struct {
|
||||
}
|
||||
|
||||
type TStep struct {
|
||||
Name string `json:"name"`
|
||||
Request *TRequest `json:"request"`
|
||||
TestCase *TestCase `json:"testcase"`
|
||||
Variables Variables `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"`
|
||||
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"`
|
||||
}
|
||||
|
||||
// interface for all types of steps
|
||||
|
||||
10
step.go
10
step.go
@@ -8,7 +8,7 @@ func Step(name string) *step {
|
||||
TStep: &TStep{
|
||||
Name: name,
|
||||
Request: &TRequest{},
|
||||
Variables: make(Variables),
|
||||
Variables: make(map[string]interface{}),
|
||||
},
|
||||
}
|
||||
}
|
||||
@@ -23,7 +23,7 @@ func (s *step) WithRunner(runner *Runner) *step {
|
||||
return s
|
||||
}
|
||||
|
||||
func (s *step) WithVariables(variables Variables) *step {
|
||||
func (s *step) WithVariables(variables map[string]interface{}) *step {
|
||||
s.TStep.Variables = variables
|
||||
return s
|
||||
}
|
||||
@@ -136,17 +136,17 @@ func (s *requestWithOptionalArgs) SetAuth(auth map[string]string) *requestWithOp
|
||||
return s
|
||||
}
|
||||
|
||||
func (s *requestWithOptionalArgs) WithParams(params Params) *requestWithOptionalArgs {
|
||||
func (s *requestWithOptionalArgs) WithParams(params map[string]interface{}) *requestWithOptionalArgs {
|
||||
s.step.Request.Params = params
|
||||
return s
|
||||
}
|
||||
|
||||
func (s *requestWithOptionalArgs) WithHeaders(headers Headers) *requestWithOptionalArgs {
|
||||
func (s *requestWithOptionalArgs) WithHeaders(headers map[string]string) *requestWithOptionalArgs {
|
||||
s.step.Request.Headers = headers
|
||||
return s
|
||||
}
|
||||
|
||||
func (s *requestWithOptionalArgs) WithCookies(cookies Cookies) *requestWithOptionalArgs {
|
||||
func (s *requestWithOptionalArgs) WithCookies(cookies map[string]string) *requestWithOptionalArgs {
|
||||
s.step.Request.Cookies = cookies
|
||||
return s
|
||||
}
|
||||
|
||||
12
step_test.go
12
step_test.go
@@ -7,17 +7,17 @@ import (
|
||||
var (
|
||||
stepGET = Step("get with params").
|
||||
GET("https://postman-echo.com/get").
|
||||
WithParams(Params{"foo1": "bar1", "foo2": "bar2"}).
|
||||
WithHeaders(Headers{"User-Agent": "HttpBoomer"}).
|
||||
WithCookies(Cookies{"user": "debugtalk"}).
|
||||
WithParams(map[string]interface{}{"foo1": "bar1", "foo2": "bar2"}).
|
||||
WithHeaders(map[string]string{"User-Agent": "HttpBoomer"}).
|
||||
WithCookies(map[string]string{"user": "debugtalk"}).
|
||||
Validate().
|
||||
AssertEqual("status_code", 200, "check status code")
|
||||
stepPOSTData = Step("post form data").
|
||||
POST("https://postman-echo.com/post").
|
||||
WithParams(Params{"foo1": "bar1", "foo2": "bar2"}).
|
||||
WithHeaders(Headers{"User-Agent": "HttpBoomer", "Content-Type": "application/x-www-form-urlencoded"}).
|
||||
WithParams(map[string]interface{}{"foo1": "bar1", "foo2": "bar2"}).
|
||||
WithHeaders(map[string]string{"User-Agent": "HttpBoomer", "Content-Type": "application/x-www-form-urlencoded"}).
|
||||
WithData("a=1&b=2").
|
||||
WithCookies(Cookies{"user": "debugtalk"}).
|
||||
WithCookies(map[string]string{"user": "debugtalk"}).
|
||||
Validate().
|
||||
AssertEqual("status_code", 200, "check status code")
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user