mirror of
https://github.com/httprunner/httprunner.git
synced 2026-07-09 06:23:52 +08:00
change: rename step structs
This commit is contained in:
@@ -109,11 +109,11 @@ func (tc *TCase) ToTestCase() (*TestCase, error) {
|
|||||||
}
|
}
|
||||||
for _, step := range tc.TestSteps {
|
for _, step := range tc.TestSteps {
|
||||||
if step.Request != nil {
|
if step.Request != nil {
|
||||||
testCase.TestSteps = append(testCase.TestSteps, &requestWithOptionalArgs{
|
testCase.TestSteps = append(testCase.TestSteps, &stepRequestWithOptionalArgs{
|
||||||
step: step,
|
step: step,
|
||||||
})
|
})
|
||||||
} else if step.TestCase != nil {
|
} else if step.TestCase != nil {
|
||||||
testCase.TestSteps = append(testCase.TestSteps, &testcaseWithOptionalArgs{
|
testCase.TestSteps = append(testCase.TestSteps, &stepTestCaseWithOptionalArgs{
|
||||||
step: step,
|
step: step,
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -142,7 +142,7 @@ func (r *hrpRunner) runStep(step IStep, config *TConfig) (stepResult *stepData,
|
|||||||
}
|
}
|
||||||
copiedStep.Variables = parsedVariables // avoid data racing
|
copiedStep.Variables = parsedVariables // avoid data racing
|
||||||
|
|
||||||
if _, ok := step.(*testcaseWithOptionalArgs); ok {
|
if _, ok := step.(*stepTestCaseWithOptionalArgs); ok {
|
||||||
// run referenced testcase
|
// run referenced testcase
|
||||||
log.Info().Str("testcase", copiedStep.Name).Msg("run referenced testcase")
|
log.Info().Str("testcase", copiedStep.Name).Msg("run referenced testcase")
|
||||||
// TODO: override testcase config
|
// TODO: override testcase config
|
||||||
|
|||||||
76
step.go
76
step.go
@@ -67,213 +67,213 @@ func (s *TStep) SetupHook(hook string) *TStep {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// GET makes a HTTP GET request.
|
// GET makes a HTTP GET request.
|
||||||
func (s *TStep) GET(url string) *requestWithOptionalArgs {
|
func (s *TStep) GET(url string) *stepRequestWithOptionalArgs {
|
||||||
s.Request = &Request{
|
s.Request = &Request{
|
||||||
Method: httpGET,
|
Method: httpGET,
|
||||||
URL: url,
|
URL: url,
|
||||||
}
|
}
|
||||||
return &requestWithOptionalArgs{
|
return &stepRequestWithOptionalArgs{
|
||||||
step: s,
|
step: s,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// HEAD makes a HTTP HEAD request.
|
// HEAD makes a HTTP HEAD request.
|
||||||
func (s *TStep) HEAD(url string) *requestWithOptionalArgs {
|
func (s *TStep) HEAD(url string) *stepRequestWithOptionalArgs {
|
||||||
s.Request = &Request{
|
s.Request = &Request{
|
||||||
Method: httpHEAD,
|
Method: httpHEAD,
|
||||||
URL: url,
|
URL: url,
|
||||||
}
|
}
|
||||||
return &requestWithOptionalArgs{
|
return &stepRequestWithOptionalArgs{
|
||||||
step: s,
|
step: s,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// POST makes a HTTP POST request.
|
// POST makes a HTTP POST request.
|
||||||
func (s *TStep) POST(url string) *requestWithOptionalArgs {
|
func (s *TStep) POST(url string) *stepRequestWithOptionalArgs {
|
||||||
s.Request = &Request{
|
s.Request = &Request{
|
||||||
Method: httpPOST,
|
Method: httpPOST,
|
||||||
URL: url,
|
URL: url,
|
||||||
}
|
}
|
||||||
return &requestWithOptionalArgs{
|
return &stepRequestWithOptionalArgs{
|
||||||
step: s,
|
step: s,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// PUT makes a HTTP PUT request.
|
// PUT makes a HTTP PUT request.
|
||||||
func (s *TStep) PUT(url string) *requestWithOptionalArgs {
|
func (s *TStep) PUT(url string) *stepRequestWithOptionalArgs {
|
||||||
s.Request = &Request{
|
s.Request = &Request{
|
||||||
Method: httpPUT,
|
Method: httpPUT,
|
||||||
URL: url,
|
URL: url,
|
||||||
}
|
}
|
||||||
return &requestWithOptionalArgs{
|
return &stepRequestWithOptionalArgs{
|
||||||
step: s,
|
step: s,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// DELETE makes a HTTP DELETE request.
|
// DELETE makes a HTTP DELETE request.
|
||||||
func (s *TStep) DELETE(url string) *requestWithOptionalArgs {
|
func (s *TStep) DELETE(url string) *stepRequestWithOptionalArgs {
|
||||||
s.Request = &Request{
|
s.Request = &Request{
|
||||||
Method: httpDELETE,
|
Method: httpDELETE,
|
||||||
URL: url,
|
URL: url,
|
||||||
}
|
}
|
||||||
return &requestWithOptionalArgs{
|
return &stepRequestWithOptionalArgs{
|
||||||
step: s,
|
step: s,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// OPTIONS makes a HTTP OPTIONS request.
|
// OPTIONS makes a HTTP OPTIONS request.
|
||||||
func (s *TStep) OPTIONS(url string) *requestWithOptionalArgs {
|
func (s *TStep) OPTIONS(url string) *stepRequestWithOptionalArgs {
|
||||||
s.Request = &Request{
|
s.Request = &Request{
|
||||||
Method: httpOPTIONS,
|
Method: httpOPTIONS,
|
||||||
URL: url,
|
URL: url,
|
||||||
}
|
}
|
||||||
return &requestWithOptionalArgs{
|
return &stepRequestWithOptionalArgs{
|
||||||
step: s,
|
step: s,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// PATCH makes a HTTP PATCH request.
|
// PATCH makes a HTTP PATCH request.
|
||||||
func (s *TStep) PATCH(url string) *requestWithOptionalArgs {
|
func (s *TStep) PATCH(url string) *stepRequestWithOptionalArgs {
|
||||||
s.Request = &Request{
|
s.Request = &Request{
|
||||||
Method: httpPATCH,
|
Method: httpPATCH,
|
||||||
URL: url,
|
URL: url,
|
||||||
}
|
}
|
||||||
return &requestWithOptionalArgs{
|
return &stepRequestWithOptionalArgs{
|
||||||
step: s,
|
step: s,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// CallRefCase calls a referenced testcase.
|
// CallRefCase calls a referenced testcase.
|
||||||
func (s *TStep) CallRefCase(tc *TestCase) *testcaseWithOptionalArgs {
|
func (s *TStep) CallRefCase(tc *TestCase) *stepTestCaseWithOptionalArgs {
|
||||||
s.TestCase = tc
|
s.TestCase = tc
|
||||||
return &testcaseWithOptionalArgs{
|
return &stepTestCaseWithOptionalArgs{
|
||||||
step: s,
|
step: s,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// implements IStep interface
|
// implements IStep interface
|
||||||
type requestWithOptionalArgs struct {
|
type stepRequestWithOptionalArgs struct {
|
||||||
step *TStep
|
step *TStep
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetVerify sets whether to verify SSL for current HTTP request.
|
// SetVerify sets whether to verify SSL for current HTTP request.
|
||||||
func (s *requestWithOptionalArgs) SetVerify(verify bool) *requestWithOptionalArgs {
|
func (s *stepRequestWithOptionalArgs) SetVerify(verify bool) *stepRequestWithOptionalArgs {
|
||||||
s.step.Request.Verify = verify
|
s.step.Request.Verify = verify
|
||||||
return s
|
return s
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetTimeout sets timeout for current HTTP request.
|
// SetTimeout sets timeout for current HTTP request.
|
||||||
func (s *requestWithOptionalArgs) SetTimeout(timeout float32) *requestWithOptionalArgs {
|
func (s *stepRequestWithOptionalArgs) SetTimeout(timeout float32) *stepRequestWithOptionalArgs {
|
||||||
s.step.Request.Timeout = timeout
|
s.step.Request.Timeout = timeout
|
||||||
return s
|
return s
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetProxies sets proxies for current HTTP request.
|
// SetProxies sets proxies for current HTTP request.
|
||||||
func (s *requestWithOptionalArgs) SetProxies(proxies map[string]string) *requestWithOptionalArgs {
|
func (s *stepRequestWithOptionalArgs) SetProxies(proxies map[string]string) *stepRequestWithOptionalArgs {
|
||||||
// TODO
|
// TODO
|
||||||
return s
|
return s
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetAllowRedirects sets whether to allow redirects for current HTTP request.
|
// SetAllowRedirects sets whether to allow redirects for current HTTP request.
|
||||||
func (s *requestWithOptionalArgs) SetAllowRedirects(allowRedirects bool) *requestWithOptionalArgs {
|
func (s *stepRequestWithOptionalArgs) SetAllowRedirects(allowRedirects bool) *stepRequestWithOptionalArgs {
|
||||||
s.step.Request.AllowRedirects = allowRedirects
|
s.step.Request.AllowRedirects = allowRedirects
|
||||||
return s
|
return s
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetAuth sets auth for current HTTP request.
|
// SetAuth sets auth for current HTTP request.
|
||||||
func (s *requestWithOptionalArgs) SetAuth(auth map[string]string) *requestWithOptionalArgs {
|
func (s *stepRequestWithOptionalArgs) SetAuth(auth map[string]string) *stepRequestWithOptionalArgs {
|
||||||
// TODO
|
// TODO
|
||||||
return s
|
return s
|
||||||
}
|
}
|
||||||
|
|
||||||
// WithParams sets HTTP request params for current step.
|
// WithParams sets HTTP request params for current step.
|
||||||
func (s *requestWithOptionalArgs) WithParams(params map[string]interface{}) *requestWithOptionalArgs {
|
func (s *stepRequestWithOptionalArgs) WithParams(params map[string]interface{}) *stepRequestWithOptionalArgs {
|
||||||
s.step.Request.Params = params
|
s.step.Request.Params = params
|
||||||
return s
|
return s
|
||||||
}
|
}
|
||||||
|
|
||||||
// WithHeaders sets HTTP request headers for current step.
|
// WithHeaders sets HTTP request headers for current step.
|
||||||
func (s *requestWithOptionalArgs) WithHeaders(headers map[string]string) *requestWithOptionalArgs {
|
func (s *stepRequestWithOptionalArgs) WithHeaders(headers map[string]string) *stepRequestWithOptionalArgs {
|
||||||
s.step.Request.Headers = headers
|
s.step.Request.Headers = headers
|
||||||
return s
|
return s
|
||||||
}
|
}
|
||||||
|
|
||||||
// WithCookies sets HTTP request cookies for current step.
|
// WithCookies sets HTTP request cookies for current step.
|
||||||
func (s *requestWithOptionalArgs) WithCookies(cookies map[string]string) *requestWithOptionalArgs {
|
func (s *stepRequestWithOptionalArgs) WithCookies(cookies map[string]string) *stepRequestWithOptionalArgs {
|
||||||
s.step.Request.Cookies = cookies
|
s.step.Request.Cookies = cookies
|
||||||
return s
|
return s
|
||||||
}
|
}
|
||||||
|
|
||||||
// WithBody sets HTTP request body for current step.
|
// WithBody sets HTTP request body for current step.
|
||||||
func (s *requestWithOptionalArgs) WithBody(body interface{}) *requestWithOptionalArgs {
|
func (s *stepRequestWithOptionalArgs) WithBody(body interface{}) *stepRequestWithOptionalArgs {
|
||||||
s.step.Request.Body = body
|
s.step.Request.Body = body
|
||||||
return s
|
return s
|
||||||
}
|
}
|
||||||
|
|
||||||
// TeardownHook adds a teardown hook for current teststep.
|
// TeardownHook adds a teardown hook for current teststep.
|
||||||
func (s *requestWithOptionalArgs) TeardownHook(hook string) *requestWithOptionalArgs {
|
func (s *stepRequestWithOptionalArgs) TeardownHook(hook string) *stepRequestWithOptionalArgs {
|
||||||
s.step.TeardownHooks = append(s.step.TeardownHooks, hook)
|
s.step.TeardownHooks = append(s.step.TeardownHooks, hook)
|
||||||
return s
|
return s
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validate switches to step validation.
|
// Validate switches to step validation.
|
||||||
func (s *requestWithOptionalArgs) Validate() *stepRequestValidation {
|
func (s *stepRequestWithOptionalArgs) Validate() *stepRequestValidation {
|
||||||
return &stepRequestValidation{
|
return &stepRequestValidation{
|
||||||
step: s.step,
|
step: s.step,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Extract switches to step extraction.
|
// Extract switches to step extraction.
|
||||||
func (s *requestWithOptionalArgs) Extract() *stepRequestExtraction {
|
func (s *stepRequestWithOptionalArgs) Extract() *stepRequestExtraction {
|
||||||
s.step.Extract = make(map[string]string)
|
s.step.Extract = make(map[string]string)
|
||||||
return &stepRequestExtraction{
|
return &stepRequestExtraction{
|
||||||
step: s.step,
|
step: s.step,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *requestWithOptionalArgs) Name() string {
|
func (s *stepRequestWithOptionalArgs) Name() string {
|
||||||
if s.step.Name != "" {
|
if s.step.Name != "" {
|
||||||
return s.step.Name
|
return s.step.Name
|
||||||
}
|
}
|
||||||
return fmt.Sprintf("%s %s", s.step.Request.Method, s.step.Request.URL)
|
return fmt.Sprintf("%s %s", s.step.Request.Method, s.step.Request.URL)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *requestWithOptionalArgs) Type() string {
|
func (s *stepRequestWithOptionalArgs) Type() string {
|
||||||
return fmt.Sprintf("request-%v", s.step.Request.Method)
|
return fmt.Sprintf("request-%v", s.step.Request.Method)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *requestWithOptionalArgs) ToStruct() *TStep {
|
func (s *stepRequestWithOptionalArgs) ToStruct() *TStep {
|
||||||
return s.step
|
return s.step
|
||||||
}
|
}
|
||||||
|
|
||||||
// implements IStep interface
|
// implements IStep interface
|
||||||
type testcaseWithOptionalArgs struct {
|
type stepTestCaseWithOptionalArgs struct {
|
||||||
step *TStep
|
step *TStep
|
||||||
}
|
}
|
||||||
|
|
||||||
// TeardownHook adds a teardown hook for current teststep.
|
// TeardownHook adds a teardown hook for current teststep.
|
||||||
func (s *testcaseWithOptionalArgs) TeardownHook(hook string) *testcaseWithOptionalArgs {
|
func (s *stepTestCaseWithOptionalArgs) TeardownHook(hook string) *stepTestCaseWithOptionalArgs {
|
||||||
s.step.TeardownHooks = append(s.step.TeardownHooks, hook)
|
s.step.TeardownHooks = append(s.step.TeardownHooks, hook)
|
||||||
return s
|
return s
|
||||||
}
|
}
|
||||||
|
|
||||||
// Export specifies variable names to export from referenced testcase for current step.
|
// Export specifies variable names to export from referenced testcase for current step.
|
||||||
func (s *testcaseWithOptionalArgs) Export(names ...string) *testcaseWithOptionalArgs {
|
func (s *stepTestCaseWithOptionalArgs) Export(names ...string) *stepTestCaseWithOptionalArgs {
|
||||||
s.step.Export = append(s.step.Export, names...)
|
s.step.Export = append(s.step.Export, names...)
|
||||||
return s
|
return s
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *testcaseWithOptionalArgs) Name() string {
|
func (s *stepTestCaseWithOptionalArgs) Name() string {
|
||||||
if s.step.Name != "" {
|
if s.step.Name != "" {
|
||||||
return s.step.Name
|
return s.step.Name
|
||||||
}
|
}
|
||||||
return s.step.TestCase.Config.Name
|
return s.step.TestCase.Config.Name
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *testcaseWithOptionalArgs) Type() string {
|
func (s *stepTestCaseWithOptionalArgs) Type() string {
|
||||||
return "testcase"
|
return "testcase"
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *testcaseWithOptionalArgs) ToStruct() *TStep {
|
func (s *stepTestCaseWithOptionalArgs) ToStruct() *TStep {
|
||||||
return s.step
|
return s.step
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user