mirror of
https://github.com/httprunner/httprunner.git
synced 2026-09-04 23:16:57 +08:00
refactor: make models private
This commit is contained in:
@@ -65,9 +65,9 @@ func (b *Boomer) convertBoomerTask(testcase *TestCase) *boomer.Task {
|
|||||||
stepData, err := runner.runStep(step, config)
|
stepData, err := runner.runStep(step, config)
|
||||||
elapsed := time.Since(start).Nanoseconds() / int64(time.Millisecond)
|
elapsed := time.Since(start).Nanoseconds() / int64(time.Millisecond)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
b.RecordSuccess(step.Type(), step.Name(), elapsed, stepData.ResponseLength)
|
b.RecordSuccess(step.getType(), step.name(), elapsed, stepData.responseLength)
|
||||||
} else {
|
} else {
|
||||||
b.RecordFailure(step.Type(), step.Name(), elapsed, err.Error())
|
b.RecordFailure(step.getType(), step.name(), elapsed, err.Error())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
+1
-1
@@ -15,7 +15,7 @@ func (tc *TestCase) ToTCase() (*TCase, error) {
|
|||||||
Config: tc.Config,
|
Config: tc.Config,
|
||||||
}
|
}
|
||||||
for _, step := range tc.TestSteps {
|
for _, step := range tc.TestSteps {
|
||||||
tCase.TestSteps = append(tCase.TestSteps, step.ToStruct())
|
tCase.TestSteps = append(tCase.TestSteps, step.toStruct())
|
||||||
}
|
}
|
||||||
return &tCase, nil
|
return &tCase, nil
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -22,4 +22,4 @@ Copyright 2021 debugtalk
|
|||||||
* [hrp har2case](hrp_har2case.md) - Convert HAR to json/yaml testcase files
|
* [hrp har2case](hrp_har2case.md) - Convert HAR to json/yaml testcase files
|
||||||
* [hrp run](hrp_run.md) - run API test
|
* [hrp run](hrp_run.md) - run API test
|
||||||
|
|
||||||
###### Auto generated by spf13/cobra on 2-Dec-2021
|
###### Auto generated by spf13/cobra on 7-Dec-2021
|
||||||
|
|||||||
@@ -39,4 +39,4 @@ hrp boom [flags]
|
|||||||
|
|
||||||
* [hrp](hrp.md) - One-stop solution for HTTP(S) testing.
|
* [hrp](hrp.md) - One-stop solution for HTTP(S) testing.
|
||||||
|
|
||||||
###### Auto generated by spf13/cobra on 2-Dec-2021
|
###### Auto generated by spf13/cobra on 7-Dec-2021
|
||||||
|
|||||||
@@ -23,4 +23,4 @@ hrp har2case harPath... [flags]
|
|||||||
|
|
||||||
* [hrp](hrp.md) - One-stop solution for HTTP(S) testing.
|
* [hrp](hrp.md) - One-stop solution for HTTP(S) testing.
|
||||||
|
|
||||||
###### Auto generated by spf13/cobra on 2-Dec-2021
|
###### Auto generated by spf13/cobra on 7-Dec-2021
|
||||||
|
|||||||
+1
-1
@@ -30,4 +30,4 @@ hrp run path... [flags]
|
|||||||
|
|
||||||
* [hrp](hrp.md) - One-stop solution for HTTP(S) testing.
|
* [hrp](hrp.md) - One-stop solution for HTTP(S) testing.
|
||||||
|
|
||||||
###### Auto generated by spf13/cobra on 2-Dec-2021
|
###### Auto generated by spf13/cobra on 7-Dec-2021
|
||||||
|
|||||||
+3
-3
@@ -18,14 +18,14 @@ func (s *stepRequestExtraction) Validate() *stepRequestValidation {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *stepRequestExtraction) Name() string {
|
func (s *stepRequestExtraction) name() string {
|
||||||
return s.step.Name
|
return s.step.Name
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *stepRequestExtraction) Type() string {
|
func (s *stepRequestExtraction) getType() string {
|
||||||
return fmt.Sprintf("request-%v", s.step.Request.Method)
|
return fmt.Sprintf("request-%v", s.step.Request.Method)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *stepRequestExtraction) ToStruct() *TStep {
|
func (s *stepRequestExtraction) toStruct() *TStep {
|
||||||
return s.step
|
return s.step
|
||||||
}
|
}
|
||||||
|
|||||||
+6
-6
@@ -147,8 +147,8 @@ func (h *HAR) prepareTestStep(entry *Entry) (*hrp.TStep, error) {
|
|||||||
|
|
||||||
tStep := &TStep{
|
tStep := &TStep{
|
||||||
TStep: hrp.TStep{
|
TStep: hrp.TStep{
|
||||||
Request: &hrp.TRequest{},
|
Request: &hrp.Request{},
|
||||||
Validators: make([]hrp.TValidator, 0),
|
Validators: make([]hrp.Validator, 0),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
if err := tStep.makeRequestMethod(entry); err != nil {
|
if err := tStep.makeRequestMethod(entry); err != nil {
|
||||||
@@ -180,7 +180,7 @@ type TStep struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *TStep) makeRequestMethod(entry *Entry) error {
|
func (s *TStep) makeRequestMethod(entry *Entry) error {
|
||||||
s.Request.Method = hrp.EnumHTTPMethod(entry.Request.Method)
|
s.Request.Method = entry.Request.Method
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -258,7 +258,7 @@ func (s *TStep) makeRequestBody(entry *Entry) error {
|
|||||||
|
|
||||||
func (s *TStep) makeValidate(entry *Entry) error {
|
func (s *TStep) makeValidate(entry *Entry) error {
|
||||||
// make validator for response status code
|
// make validator for response status code
|
||||||
s.Validators = append(s.Validators, hrp.TValidator{
|
s.Validators = append(s.Validators, hrp.Validator{
|
||||||
Check: "status_code",
|
Check: "status_code",
|
||||||
Assert: "equals",
|
Assert: "equals",
|
||||||
Expect: entry.Response.Status,
|
Expect: entry.Response.Status,
|
||||||
@@ -269,7 +269,7 @@ func (s *TStep) makeValidate(entry *Entry) error {
|
|||||||
for _, header := range entry.Response.Headers {
|
for _, header := range entry.Response.Headers {
|
||||||
// assert Content-Type
|
// assert Content-Type
|
||||||
if strings.EqualFold(header.Name, "Content-Type") {
|
if strings.EqualFold(header.Name, "Content-Type") {
|
||||||
s.Validators = append(s.Validators, hrp.TValidator{
|
s.Validators = append(s.Validators, hrp.Validator{
|
||||||
Check: "headers.Content-Type",
|
Check: "headers.Content-Type",
|
||||||
Assert: "equals",
|
Assert: "equals",
|
||||||
Expect: header.Value,
|
Expect: header.Value,
|
||||||
@@ -318,7 +318,7 @@ func (s *TStep) makeValidate(entry *Entry) error {
|
|||||||
case []interface{}:
|
case []interface{}:
|
||||||
continue
|
continue
|
||||||
default:
|
default:
|
||||||
s.Validators = append(s.Validators, hrp.TValidator{
|
s.Validators = append(s.Validators, hrp.Validator{
|
||||||
Check: fmt.Sprintf("body.%s", key),
|
Check: fmt.Sprintf("body.%s", key),
|
||||||
Assert: "equals",
|
Assert: "equals",
|
||||||
Expect: v,
|
Expect: v,
|
||||||
|
|||||||
@@ -1,3 +1,3 @@
|
|||||||
package version
|
package version
|
||||||
|
|
||||||
const VERSION = "v0.2.1"
|
const VERSION = "v0.3.0"
|
||||||
|
|||||||
@@ -1,19 +1,17 @@
|
|||||||
package hrp
|
package hrp
|
||||||
|
|
||||||
type EnumHTTPMethod string
|
|
||||||
|
|
||||||
const (
|
const (
|
||||||
GET EnumHTTPMethod = "GET"
|
httpGET string = "GET"
|
||||||
HEAD EnumHTTPMethod = "HEAD"
|
httpHEAD string = "HEAD"
|
||||||
POST EnumHTTPMethod = "POST"
|
httpPOST string = "POST"
|
||||||
PUT EnumHTTPMethod = "PUT"
|
httpPUT string = "PUT"
|
||||||
DELETE EnumHTTPMethod = "DELETE"
|
httpDELETE string = "DELETE"
|
||||||
OPTIONS EnumHTTPMethod = "OPTIONS"
|
httpOPTIONS string = "OPTIONS"
|
||||||
PATCH EnumHTTPMethod = "PATCH"
|
httpPATCH string = "PATCH"
|
||||||
)
|
)
|
||||||
|
|
||||||
type TConfig struct {
|
type TConfig struct {
|
||||||
Name string `json:"name" yaml:"name"`
|
Name string `json:"name" yaml:"name"` // required
|
||||||
Verify bool `json:"verify,omitempty" yaml:"verify,omitempty"`
|
Verify bool `json:"verify,omitempty" yaml:"verify,omitempty"`
|
||||||
BaseURL string `json:"base_url,omitempty" yaml:"base_url,omitempty"`
|
BaseURL string `json:"base_url,omitempty" yaml:"base_url,omitempty"`
|
||||||
Variables map[string]interface{} `json:"variables,omitempty" yaml:"variables,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"`
|
Weight int `json:"weight,omitempty" yaml:"weight,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type TRequest struct {
|
type Request struct {
|
||||||
Method EnumHTTPMethod `json:"method" yaml:"method"`
|
Method string `json:"method" yaml:"method"` // required
|
||||||
URL string `json:"url" yaml:"url"`
|
URL string `json:"url" yaml:"url"` // required
|
||||||
Params map[string]interface{} `json:"params,omitempty" yaml:"params,omitempty"`
|
Params map[string]interface{} `json:"params,omitempty" yaml:"params,omitempty"`
|
||||||
Headers map[string]string `json:"headers,omitempty" yaml:"headers,omitempty"`
|
Headers map[string]string `json:"headers,omitempty" yaml:"headers,omitempty"`
|
||||||
Cookies map[string]string `json:"cookies,omitempty" yaml:"cookies,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"`
|
Verify bool `json:"verify,omitempty" yaml:"verify,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type TValidator struct {
|
type Validator struct {
|
||||||
Check string `json:"check,omitempty" yaml:"check,omitempty"` // get value with jmespath
|
Check string `json:"check" yaml:"check"` // get value with jmespath
|
||||||
Assert string `json:"assert,omitempty" yaml:"assert,omitempty"`
|
Assert string `json:"assert" yaml:"assert"`
|
||||||
Expect interface{} `json:"expect,omitempty" yaml:"expect,omitempty"`
|
Expect interface{} `json:"expect" yaml:"expect"`
|
||||||
Message string `json:"msg,omitempty" yaml:"msg,omitempty"`
|
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 {
|
type TStep struct {
|
||||||
Name string `json:"name" yaml:"name"`
|
Name string `json:"name" yaml:"name"` // required
|
||||||
Transaction string `json:"transaction,omitempty" yaml:"transaction,omitempty"`
|
Request *Request `json:"request,omitempty" yaml:"request,omitempty"`
|
||||||
Request *TRequest `json:"request,omitempty" yaml:"request,omitempty"`
|
|
||||||
TestCase *TestCase `json:"testcase,omitempty" yaml:"testcase,omitempty"`
|
TestCase *TestCase `json:"testcase,omitempty" yaml:"testcase,omitempty"`
|
||||||
Variables map[string]interface{} `json:"variables,omitempty" yaml:"variables,omitempty"`
|
Variables map[string]interface{} `json:"variables,omitempty" yaml:"variables,omitempty"`
|
||||||
SetupHooks []string `json:"setup_hooks,omitempty" yaml:"setup_hooks,omitempty"`
|
SetupHooks []string `json:"setup_hooks,omitempty" yaml:"setup_hooks,omitempty"`
|
||||||
TeardownHooks []string `json:"teardown_hooks,omitempty" yaml:"teardown_hooks,omitempty"`
|
TeardownHooks []string `json:"teardown_hooks,omitempty" yaml:"teardown_hooks,omitempty"`
|
||||||
Extract map[string]string `json:"extract,omitempty" yaml:"extract,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"`
|
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 {
|
type TCase struct {
|
||||||
Config TConfig `json:"config" yaml:"config"`
|
Config TConfig `json:"config" yaml:"config"`
|
||||||
TestSteps []*TStep `json:"teststeps" yaml:"teststeps"`
|
TestSteps []*TStep `json:"teststeps" yaml:"teststeps"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// interface for all types of steps
|
// IStep represents interface for all types for teststeps
|
||||||
type IStep interface {
|
type IStep interface {
|
||||||
Name() string
|
name() string
|
||||||
Type() string
|
getType() string
|
||||||
ToStruct() *TStep
|
toStruct() *TStep
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ITestCase represents interface for all types for testcases
|
||||||
type ITestCase interface {
|
type ITestCase interface {
|
||||||
ToTestCase() (*TestCase, error)
|
ToTestCase() (*TestCase, error)
|
||||||
ToTCase() (*TCase, error)
|
ToTCase() (*TCase, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TestCase is a container for one testcase.
|
||||||
// used for testcase runner
|
// used for testcase runner
|
||||||
type TestCase struct {
|
type TestCase struct {
|
||||||
Config TConfig
|
Config TConfig
|
||||||
@@ -86,11 +88,11 @@ type TestCasePath struct {
|
|||||||
Path string
|
Path string
|
||||||
}
|
}
|
||||||
|
|
||||||
type TestCaseSummary struct{}
|
type testCaseSummary struct{}
|
||||||
|
|
||||||
type StepData struct {
|
type stepData struct {
|
||||||
Name string // step name
|
name string // step name
|
||||||
Success bool // step execution result
|
success bool // step execution result
|
||||||
ResponseLength int64 // response body length
|
responseLength int64 // response body length
|
||||||
ExportVars map[string]interface{} // extract variables
|
exportVars map[string]interface{} // extract variables
|
||||||
}
|
}
|
||||||
|
|||||||
+6
-6
@@ -12,7 +12,7 @@ import (
|
|||||||
"github.com/httprunner/hrp/internal/builtin"
|
"github.com/httprunner/hrp/internal/builtin"
|
||||||
)
|
)
|
||||||
|
|
||||||
func NewResponseObject(t *testing.T, resp *http.Response) (*ResponseObject, error) {
|
func newResponseObject(t *testing.T, resp *http.Response) (*responseObject, error) {
|
||||||
// prepare response headers
|
// prepare response headers
|
||||||
headers := make(map[string]string)
|
headers := make(map[string]string)
|
||||||
for k, v := range resp.Header {
|
for k, v := range resp.Header {
|
||||||
@@ -58,7 +58,7 @@ func NewResponseObject(t *testing.T, resp *http.Response) (*ResponseObject, erro
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return &ResponseObject{
|
return &responseObject{
|
||||||
t: t,
|
t: t,
|
||||||
respObjMeta: data,
|
respObjMeta: data,
|
||||||
}, nil
|
}, nil
|
||||||
@@ -71,13 +71,13 @@ type respObjMeta struct {
|
|||||||
Body interface{} `json:"body"`
|
Body interface{} `json:"body"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type ResponseObject struct {
|
type responseObject struct {
|
||||||
t *testing.T
|
t *testing.T
|
||||||
respObjMeta interface{}
|
respObjMeta interface{}
|
||||||
validationResults map[string]interface{}
|
validationResults map[string]interface{}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (v *ResponseObject) Extract(extractors map[string]string) map[string]interface{} {
|
func (v *responseObject) Extract(extractors map[string]string) map[string]interface{} {
|
||||||
if extractors == nil {
|
if extractors == nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@@ -93,7 +93,7 @@ func (v *ResponseObject) Extract(extractors map[string]string) map[string]interf
|
|||||||
return extractMapping
|
return extractMapping
|
||||||
}
|
}
|
||||||
|
|
||||||
func (v *ResponseObject) Validate(validators []TValidator, variablesMapping map[string]interface{}) (err error) {
|
func (v *responseObject) Validate(validators []Validator, variablesMapping map[string]interface{}) (err error) {
|
||||||
for _, validator := range validators {
|
for _, validator := range validators {
|
||||||
// parse check value
|
// parse check value
|
||||||
checkItem := validator.Check
|
checkItem := validator.Check
|
||||||
@@ -133,7 +133,7 @@ func (v *ResponseObject) Validate(validators []TValidator, variablesMapping map[
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (v *ResponseObject) searchJmespath(expr string) interface{} {
|
func (v *responseObject) searchJmespath(expr string) interface{} {
|
||||||
checkValue, err := jmespath.Search(expr, v.respObjMeta)
|
checkValue, err := jmespath.Search(expr, v.respObjMeta)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error().Str("expr", expr).Err(err).Msg("search jmespath failed")
|
log.Error().Str("expr", expr).Err(err).Msg("search jmespath failed")
|
||||||
|
|||||||
@@ -113,12 +113,12 @@ func (r *Runner) runCase(testcase *TestCase) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Runner) runStep(step IStep, config *TConfig) (stepData *StepData, err error) {
|
func (r *Runner) runStep(step IStep, config *TConfig) (stepResult *stepData, err error) {
|
||||||
log.Info().Str("step", step.Name()).Msg("run step start")
|
log.Info().Str("step", step.name()).Msg("run step start")
|
||||||
|
|
||||||
// copy step to avoid data racing
|
// copy step to avoid data racing
|
||||||
copiedStep := &TStep{}
|
copiedStep := &TStep{}
|
||||||
if err = copier.Copy(copiedStep, step.ToStruct()); err != nil {
|
if err = copier.Copy(copiedStep, step.toStruct()); err != nil {
|
||||||
log.Error().Err(err).Msg("copy step data failed")
|
log.Error().Err(err).Msg("copy step data failed")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -142,7 +142,7 @@ func (r *Runner) runStep(step IStep, config *TConfig) (stepData *StepData, err e
|
|||||||
// 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
|
||||||
stepData, err = r.runStepTestCase(copiedStep)
|
stepResult, err = r.runStepTestCase(copiedStep)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error().Err(err).Msg("run referenced testcase step failed")
|
log.Error().Err(err).Msg("run referenced testcase step failed")
|
||||||
return
|
return
|
||||||
@@ -150,7 +150,7 @@ func (r *Runner) runStep(step IStep, config *TConfig) (stepData *StepData, err e
|
|||||||
} else {
|
} else {
|
||||||
// run request
|
// run request
|
||||||
copiedStep.Request.URL = buildURL(config.BaseURL, copiedStep.Request.URL) // avoid data racing
|
copiedStep.Request.URL = buildURL(config.BaseURL, copiedStep.Request.URL) // avoid data racing
|
||||||
stepData, err = r.runStepRequest(copiedStep)
|
stepResult, err = r.runStepRequest(copiedStep)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error().Err(err).Msg("run request step failed")
|
log.Error().Err(err).Msg("run request step failed")
|
||||||
return
|
return
|
||||||
@@ -158,23 +158,23 @@ func (r *Runner) runStep(step IStep, config *TConfig) (stepData *StepData, err e
|
|||||||
}
|
}
|
||||||
|
|
||||||
// update extracted variables
|
// update extracted variables
|
||||||
for k, v := range stepData.ExportVars {
|
for k, v := range stepResult.exportVars {
|
||||||
r.sessionVariables[k] = v
|
r.sessionVariables[k] = v
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Info().
|
log.Info().
|
||||||
Str("step", step.Name()).
|
Str("step", step.name()).
|
||||||
Bool("success", stepData.Success).
|
Bool("success", stepResult.success).
|
||||||
Interface("exportVars", stepData.ExportVars).
|
Interface("exportVars", stepResult.exportVars).
|
||||||
Msg("run step end")
|
Msg("run step end")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Runner) runStepRequest(step *TStep) (stepData *StepData, err error) {
|
func (r *Runner) runStepRequest(step *TStep) (stepResult *stepData, err error) {
|
||||||
stepData = &StepData{
|
stepResult = &stepData{
|
||||||
Name: step.Name,
|
name: step.Name,
|
||||||
Success: false,
|
success: false,
|
||||||
ResponseLength: 0,
|
responseLength: 0,
|
||||||
}
|
}
|
||||||
|
|
||||||
rawUrl := step.Request.URL
|
rawUrl := step.Request.URL
|
||||||
@@ -310,7 +310,7 @@ func (r *Runner) runStepRequest(step *TStep) (stepData *StepData, err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// new response object
|
// new response object
|
||||||
respObj, err := NewResponseObject(r.t, resp)
|
respObj, err := newResponseObject(r.t, resp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = errors.Wrap(err, "init ResponseObject error")
|
err = errors.Wrap(err, "init ResponseObject error")
|
||||||
return
|
return
|
||||||
@@ -319,7 +319,7 @@ func (r *Runner) runStepRequest(step *TStep) (stepData *StepData, err error) {
|
|||||||
// extract variables from response
|
// extract variables from response
|
||||||
extractors := step.Extract
|
extractors := step.Extract
|
||||||
extractMapping := respObj.Extract(extractors)
|
extractMapping := respObj.Extract(extractors)
|
||||||
stepData.ExportVars = extractMapping
|
stepResult.exportVars = extractMapping
|
||||||
|
|
||||||
// override step variables with extracted variables
|
// override step variables with extracted variables
|
||||||
stepVariables := mergeVariables(step.Variables, extractMapping)
|
stepVariables := mergeVariables(step.Variables, extractMapping)
|
||||||
@@ -330,15 +330,15 @@ func (r *Runner) runStepRequest(step *TStep) (stepData *StepData, err error) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
stepData.Success = true
|
stepResult.success = true
|
||||||
stepData.ResponseLength = resp.ContentLength
|
stepResult.responseLength = resp.ContentLength
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Runner) runStepTestCase(step *TStep) (stepData *StepData, err error) {
|
func (r *Runner) runStepTestCase(step *TStep) (stepResult *stepData, err error) {
|
||||||
stepData = &StepData{
|
stepResult = &stepData{
|
||||||
Name: step.Name,
|
name: step.Name,
|
||||||
Success: false,
|
success: false,
|
||||||
}
|
}
|
||||||
testcase := step.TestCase
|
testcase := step.TestCase
|
||||||
err = r.runCase(testcase)
|
err = r.runCase(testcase)
|
||||||
@@ -371,8 +371,8 @@ func (r *Runner) parseConfig(config *TConfig) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Runner) GetSummary() *TestCaseSummary {
|
func (r *Runner) GetSummary() *testCaseSummary {
|
||||||
return &TestCaseSummary{}
|
return &testCaseSummary{}
|
||||||
}
|
}
|
||||||
|
|
||||||
func setBodyBytes(req *http.Request, data []byte) {
|
func setBodyBytes(req *http.Request, data []byte) {
|
||||||
|
|||||||
@@ -26,8 +26,8 @@ func (s *step) SetupHook(hook string) *step {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *step) GET(url string) *requestWithOptionalArgs {
|
func (s *step) GET(url string) *requestWithOptionalArgs {
|
||||||
s.TStep.Request = &TRequest{
|
s.TStep.Request = &Request{
|
||||||
Method: GET,
|
Method: httpGET,
|
||||||
URL: url,
|
URL: url,
|
||||||
}
|
}
|
||||||
return &requestWithOptionalArgs{
|
return &requestWithOptionalArgs{
|
||||||
@@ -36,8 +36,8 @@ func (s *step) GET(url string) *requestWithOptionalArgs {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *step) HEAD(url string) *requestWithOptionalArgs {
|
func (s *step) HEAD(url string) *requestWithOptionalArgs {
|
||||||
s.TStep.Request = &TRequest{
|
s.TStep.Request = &Request{
|
||||||
Method: HEAD,
|
Method: httpHEAD,
|
||||||
URL: url,
|
URL: url,
|
||||||
}
|
}
|
||||||
return &requestWithOptionalArgs{
|
return &requestWithOptionalArgs{
|
||||||
@@ -46,8 +46,8 @@ func (s *step) HEAD(url string) *requestWithOptionalArgs {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *step) POST(url string) *requestWithOptionalArgs {
|
func (s *step) POST(url string) *requestWithOptionalArgs {
|
||||||
s.TStep.Request = &TRequest{
|
s.TStep.Request = &Request{
|
||||||
Method: POST,
|
Method: httpPOST,
|
||||||
URL: url,
|
URL: url,
|
||||||
}
|
}
|
||||||
return &requestWithOptionalArgs{
|
return &requestWithOptionalArgs{
|
||||||
@@ -56,8 +56,8 @@ func (s *step) POST(url string) *requestWithOptionalArgs {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *step) PUT(url string) *requestWithOptionalArgs {
|
func (s *step) PUT(url string) *requestWithOptionalArgs {
|
||||||
s.TStep.Request = &TRequest{
|
s.TStep.Request = &Request{
|
||||||
Method: PUT,
|
Method: httpPUT,
|
||||||
URL: url,
|
URL: url,
|
||||||
}
|
}
|
||||||
return &requestWithOptionalArgs{
|
return &requestWithOptionalArgs{
|
||||||
@@ -66,8 +66,8 @@ func (s *step) PUT(url string) *requestWithOptionalArgs {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *step) DELETE(url string) *requestWithOptionalArgs {
|
func (s *step) DELETE(url string) *requestWithOptionalArgs {
|
||||||
s.TStep.Request = &TRequest{
|
s.TStep.Request = &Request{
|
||||||
Method: DELETE,
|
Method: httpDELETE,
|
||||||
URL: url,
|
URL: url,
|
||||||
}
|
}
|
||||||
return &requestWithOptionalArgs{
|
return &requestWithOptionalArgs{
|
||||||
@@ -76,8 +76,8 @@ func (s *step) DELETE(url string) *requestWithOptionalArgs {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *step) OPTIONS(url string) *requestWithOptionalArgs {
|
func (s *step) OPTIONS(url string) *requestWithOptionalArgs {
|
||||||
s.TStep.Request = &TRequest{
|
s.TStep.Request = &Request{
|
||||||
Method: OPTIONS,
|
Method: httpOPTIONS,
|
||||||
URL: url,
|
URL: url,
|
||||||
}
|
}
|
||||||
return &requestWithOptionalArgs{
|
return &requestWithOptionalArgs{
|
||||||
@@ -86,8 +86,8 @@ func (s *step) OPTIONS(url string) *requestWithOptionalArgs {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *step) PATCH(url string) *requestWithOptionalArgs {
|
func (s *step) PATCH(url string) *requestWithOptionalArgs {
|
||||||
s.TStep.Request = &TRequest{
|
s.TStep.Request = &Request{
|
||||||
Method: PATCH,
|
Method: httpPATCH,
|
||||||
URL: url,
|
URL: url,
|
||||||
}
|
}
|
||||||
return &requestWithOptionalArgs{
|
return &requestWithOptionalArgs{
|
||||||
@@ -171,18 +171,18 @@ func (s *requestWithOptionalArgs) Extract() *stepRequestExtraction {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *requestWithOptionalArgs) Name() string {
|
func (s *requestWithOptionalArgs) 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 *requestWithOptionalArgs) getType() 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 *requestWithOptionalArgs) toStruct() *TStep {
|
||||||
return s.step
|
return s.step
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -201,17 +201,17 @@ func (s *testcaseWithOptionalArgs) Export(names ...string) *testcaseWithOptional
|
|||||||
return s
|
return s
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *testcaseWithOptionalArgs) Name() string {
|
func (s *testcaseWithOptionalArgs) 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 *testcaseWithOptionalArgs) getType() string {
|
||||||
return "testcase"
|
return "testcase"
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *testcaseWithOptionalArgs) ToStruct() *TStep {
|
func (s *testcaseWithOptionalArgs) toStruct() *TStep {
|
||||||
return s.step
|
return s.step
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-2
@@ -28,7 +28,7 @@ var (
|
|||||||
|
|
||||||
func TestRunRequestGetToStruct(t *testing.T) {
|
func TestRunRequestGetToStruct(t *testing.T) {
|
||||||
tStep := stepGET.step
|
tStep := stepGET.step
|
||||||
if tStep.Request.Method != GET {
|
if tStep.Request.Method != httpGET {
|
||||||
t.Fatalf("tStep.Request.Method != GET")
|
t.Fatalf("tStep.Request.Method != GET")
|
||||||
}
|
}
|
||||||
if tStep.Request.URL != "/get" {
|
if tStep.Request.URL != "/get" {
|
||||||
@@ -50,7 +50,7 @@ func TestRunRequestGetToStruct(t *testing.T) {
|
|||||||
|
|
||||||
func TestRunRequestPostDataToStruct(t *testing.T) {
|
func TestRunRequestPostDataToStruct(t *testing.T) {
|
||||||
tStep := stepPOSTData.step
|
tStep := stepPOSTData.step
|
||||||
if tStep.Request.Method != POST {
|
if tStep.Request.Method != httpPOST {
|
||||||
t.Fatalf("tStep.Request.Method != POST")
|
t.Fatalf("tStep.Request.Method != POST")
|
||||||
}
|
}
|
||||||
if tStep.Request.URL != "/post" {
|
if tStep.Request.URL != "/post" {
|
||||||
|
|||||||
+11
-11
@@ -9,61 +9,61 @@ type stepRequestValidation struct {
|
|||||||
step *TStep
|
step *TStep
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *stepRequestValidation) Name() string {
|
func (s *stepRequestValidation) 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 *stepRequestValidation) Type() string {
|
func (s *stepRequestValidation) getType() string {
|
||||||
return fmt.Sprintf("request-%v", s.step.Request.Method)
|
return fmt.Sprintf("request-%v", s.step.Request.Method)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *stepRequestValidation) ToStruct() *TStep {
|
func (s *stepRequestValidation) toStruct() *TStep {
|
||||||
return s.step
|
return s.step
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *stepRequestValidation) AssertEqual(jmesPath string, expected interface{}, msg string) *stepRequestValidation {
|
func (s *stepRequestValidation) AssertEqual(jmesPath string, expected interface{}, msg string) *stepRequestValidation {
|
||||||
validator := TValidator{
|
v := Validator{
|
||||||
Check: jmesPath,
|
Check: jmesPath,
|
||||||
Assert: "equals",
|
Assert: "equals",
|
||||||
Expect: expected,
|
Expect: expected,
|
||||||
Message: msg,
|
Message: msg,
|
||||||
}
|
}
|
||||||
s.step.Validators = append(s.step.Validators, validator)
|
s.step.Validators = append(s.step.Validators, v)
|
||||||
return s
|
return s
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *stepRequestValidation) AssertStartsWith(jmesPath string, expected interface{}, msg string) *stepRequestValidation {
|
func (s *stepRequestValidation) AssertStartsWith(jmesPath string, expected interface{}, msg string) *stepRequestValidation {
|
||||||
validator := TValidator{
|
v := Validator{
|
||||||
Check: jmesPath,
|
Check: jmesPath,
|
||||||
Assert: "startswith",
|
Assert: "startswith",
|
||||||
Expect: expected,
|
Expect: expected,
|
||||||
Message: msg,
|
Message: msg,
|
||||||
}
|
}
|
||||||
s.step.Validators = append(s.step.Validators, validator)
|
s.step.Validators = append(s.step.Validators, v)
|
||||||
return s
|
return s
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *stepRequestValidation) AssertEndsWith(jmesPath string, expected interface{}, msg string) *stepRequestValidation {
|
func (s *stepRequestValidation) AssertEndsWith(jmesPath string, expected interface{}, msg string) *stepRequestValidation {
|
||||||
validator := TValidator{
|
v := Validator{
|
||||||
Check: jmesPath,
|
Check: jmesPath,
|
||||||
Assert: "endswith",
|
Assert: "endswith",
|
||||||
Expect: expected,
|
Expect: expected,
|
||||||
Message: msg,
|
Message: msg,
|
||||||
}
|
}
|
||||||
s.step.Validators = append(s.step.Validators, validator)
|
s.step.Validators = append(s.step.Validators, v)
|
||||||
return s
|
return s
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *stepRequestValidation) AssertLengthEqual(jmesPath string, expected interface{}, msg string) *stepRequestValidation {
|
func (s *stepRequestValidation) AssertLengthEqual(jmesPath string, expected interface{}, msg string) *stepRequestValidation {
|
||||||
validator := TValidator{
|
v := Validator{
|
||||||
Check: jmesPath,
|
Check: jmesPath,
|
||||||
Assert: "length_equals",
|
Assert: "length_equals",
|
||||||
Expect: expected,
|
Expect: expected,
|
||||||
Message: msg,
|
Message: msg,
|
||||||
}
|
}
|
||||||
s.step.Validators = append(s.step.Validators, validator)
|
s.step.Validators = append(s.step.Validators, v)
|
||||||
return s
|
return s
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user