mirror of
https://github.com/httprunner/httprunner.git
synced 2026-08-28 11:36:56 +08:00
refactor: IStep interface
This commit is contained in:
@@ -32,11 +32,10 @@ func convertBoomerTask(testcase *TestCase) *boomer.Task {
|
|||||||
err := step.Run()
|
err := step.Run()
|
||||||
elapsed := time.Since(start).Nanoseconds() / int64(time.Millisecond)
|
elapsed := time.Since(start).Nanoseconds() / int64(time.Millisecond)
|
||||||
|
|
||||||
tStep := step.ToStruct()
|
|
||||||
if err == nil {
|
if err == nil {
|
||||||
boomer.RecordSuccess(string(tStep.Request.Method), tStep.Name, elapsed, int64(0))
|
boomer.RecordSuccess(step.Type(), step.Name(), elapsed, int64(0))
|
||||||
} else {
|
} else {
|
||||||
boomer.RecordFailure(string(tStep.Request.Method), tStep.Name, elapsed, err.Error())
|
boomer.RecordFailure(step.Type(), step.Name(), elapsed, err.Error())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
+9
-3
@@ -1,5 +1,7 @@
|
|||||||
package httpboomer
|
package httpboomer
|
||||||
|
|
||||||
|
import "fmt"
|
||||||
|
|
||||||
// implements IStep interface
|
// implements IStep interface
|
||||||
type stepRequestExtraction struct {
|
type stepRequestExtraction struct {
|
||||||
runner *Runner
|
runner *Runner
|
||||||
@@ -13,12 +15,16 @@ func (s *stepRequestExtraction) WithJmesPath(jmesPath string, varName string) *s
|
|||||||
|
|
||||||
func (s *stepRequestExtraction) Validate() *stepRequestValidation {
|
func (s *stepRequestExtraction) Validate() *stepRequestValidation {
|
||||||
return &stepRequestValidation{
|
return &stepRequestValidation{
|
||||||
TStep: s.step,
|
step: s.step,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *stepRequestExtraction) ToStruct() *TStep {
|
func (s *stepRequestExtraction) Name() string {
|
||||||
return s.step
|
return s.step.Name
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *stepRequestExtraction) Type() string {
|
||||||
|
return fmt.Sprintf("request-%v", s.step.Request.Method)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *stepRequestExtraction) Run() error {
|
func (s *stepRequestExtraction) Run() error {
|
||||||
|
|||||||
@@ -61,7 +61,8 @@ type TStep struct {
|
|||||||
|
|
||||||
// interface for all types of steps
|
// interface for all types of steps
|
||||||
type IStep interface {
|
type IStep interface {
|
||||||
ToStruct() *TStep
|
Name() string
|
||||||
|
Type() string
|
||||||
Run() error
|
Run() error
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
package httpboomer
|
package httpboomer
|
||||||
|
|
||||||
|
import "fmt"
|
||||||
|
|
||||||
func Step(name string) *step {
|
func Step(name string) *step {
|
||||||
return &step{
|
return &step{
|
||||||
runner: defaultRunner,
|
runner: defaultRunner,
|
||||||
@@ -167,7 +169,7 @@ func (s *requestWithOptionalArgs) TeardownHook(hook string) *requestWithOptional
|
|||||||
func (s *requestWithOptionalArgs) Validate() *stepRequestValidation {
|
func (s *requestWithOptionalArgs) Validate() *stepRequestValidation {
|
||||||
return &stepRequestValidation{
|
return &stepRequestValidation{
|
||||||
runner: s.runner,
|
runner: s.runner,
|
||||||
TStep: s.step,
|
step: s.step,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -178,8 +180,12 @@ func (s *requestWithOptionalArgs) Extract() *stepRequestExtraction {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *requestWithOptionalArgs) ToStruct() *TStep {
|
func (s *requestWithOptionalArgs) Name() string {
|
||||||
return s.step
|
return s.step.Name
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *requestWithOptionalArgs) Type() string {
|
||||||
|
return fmt.Sprintf("request-%v", s.step.Request.Method)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *requestWithOptionalArgs) Run() error {
|
func (s *requestWithOptionalArgs) Run() error {
|
||||||
@@ -202,8 +208,12 @@ func (s *testcaseWithOptionalArgs) Export(names ...string) *testcaseWithOptional
|
|||||||
return s
|
return s
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *testcaseWithOptionalArgs) ToStruct() *TStep {
|
func (s *testcaseWithOptionalArgs) Name() string {
|
||||||
return s.step
|
return s.step.Name
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *testcaseWithOptionalArgs) Type() string {
|
||||||
|
return "testcase"
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *testcaseWithOptionalArgs) Run() error {
|
func (s *testcaseWithOptionalArgs) Run() error {
|
||||||
|
|||||||
+2
-2
@@ -23,7 +23,7 @@ var (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func TestRunRequestGetToStruct(t *testing.T) {
|
func TestRunRequestGetToStruct(t *testing.T) {
|
||||||
tStep := stepGET.ToStruct()
|
tStep := stepGET.step
|
||||||
if tStep.Request.Method != GET {
|
if tStep.Request.Method != GET {
|
||||||
t.Fatalf("tStep.Request.Method != GET")
|
t.Fatalf("tStep.Request.Method != GET")
|
||||||
}
|
}
|
||||||
@@ -45,7 +45,7 @@ func TestRunRequestGetToStruct(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestRunRequestPostDataToStruct(t *testing.T) {
|
func TestRunRequestPostDataToStruct(t *testing.T) {
|
||||||
tStep := stepPOSTData.ToStruct()
|
tStep := stepPOSTData.step
|
||||||
if tStep.Request.Method != POST {
|
if tStep.Request.Method != POST {
|
||||||
t.Fatalf("tStep.Request.Method != POST")
|
t.Fatalf("tStep.Request.Method != POST")
|
||||||
}
|
}
|
||||||
|
|||||||
+11
-5
@@ -1,9 +1,11 @@
|
|||||||
package httpboomer
|
package httpboomer
|
||||||
|
|
||||||
|
import "fmt"
|
||||||
|
|
||||||
// implements IStep interface
|
// implements IStep interface
|
||||||
type stepRequestValidation struct {
|
type stepRequestValidation struct {
|
||||||
runner *Runner
|
runner *Runner
|
||||||
TStep *TStep
|
step *TStep
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *stepRequestValidation) AssertEqual(jmesPath string, expected interface{}, msg string) *stepRequestValidation {
|
func (s *stepRequestValidation) AssertEqual(jmesPath string, expected interface{}, msg string) *stepRequestValidation {
|
||||||
@@ -13,14 +15,18 @@ func (s *stepRequestValidation) AssertEqual(jmesPath string, expected interface{
|
|||||||
Expect: expected,
|
Expect: expected,
|
||||||
Message: msg,
|
Message: msg,
|
||||||
}
|
}
|
||||||
s.TStep.Validators = append(s.TStep.Validators, validator)
|
s.step.Validators = append(s.step.Validators, validator)
|
||||||
return s
|
return s
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *stepRequestValidation) ToStruct() *TStep {
|
func (s *stepRequestValidation) Name() string {
|
||||||
return s.TStep
|
return s.step.Name
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *stepRequestValidation) Type() string {
|
||||||
|
return fmt.Sprintf("request-%v", s.step.Request.Method)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *stepRequestValidation) Run() error {
|
func (s *stepRequestValidation) Run() error {
|
||||||
return s.runner.runStep(s.TStep)
|
return s.runner.runStep(s.step)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user