mirror of
https://github.com/httprunner/httprunner.git
synced 2026-06-09 01:39:39 +08:00
refactor: Run with config
This commit is contained in:
@@ -33,9 +33,10 @@ func convertBoomerTask(testcase *TestCase) *boomer.Task {
|
|||||||
Name: testcase.Config.Name,
|
Name: testcase.Config.Name,
|
||||||
Weight: testcase.Config.Weight,
|
Weight: testcase.Config.Weight,
|
||||||
Fn: func() {
|
Fn: func() {
|
||||||
|
config := &testcase.Config
|
||||||
for _, step := range testcase.TestSteps {
|
for _, step := range testcase.TestSteps {
|
||||||
start := time.Now()
|
start := time.Now()
|
||||||
err := step.Run()
|
err := step.Run(config)
|
||||||
elapsed := time.Since(start).Nanoseconds() / int64(time.Millisecond)
|
elapsed := time.Since(start).Nanoseconds() / int64(time.Millisecond)
|
||||||
|
|
||||||
if err == nil {
|
if err == nil {
|
||||||
|
|||||||
@@ -27,6 +27,6 @@ func (s *stepRequestExtraction) Type() string {
|
|||||||
return fmt.Sprintf("request-%v", s.step.Request.Method)
|
return fmt.Sprintf("request-%v", s.step.Request.Method)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *stepRequestExtraction) Run() error {
|
func (s *stepRequestExtraction) Run(config *TConfig) error {
|
||||||
return s.runner.runStep(s.step)
|
return s.runner.runStep(s.step)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -58,7 +58,7 @@ type TStep struct {
|
|||||||
type IStep interface {
|
type IStep interface {
|
||||||
Name() string
|
Name() string
|
||||||
Type() string
|
Type() string
|
||||||
Run() error
|
Run(config *TConfig) error
|
||||||
}
|
}
|
||||||
|
|
||||||
type TestCase struct {
|
type TestCase struct {
|
||||||
|
|||||||
@@ -32,9 +32,9 @@ func (r *Runner) Run(testcases ...*TestCase) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (r *Runner) runCase(testcase *TestCase) error {
|
func (r *Runner) runCase(testcase *TestCase) error {
|
||||||
// config := testcase.Config
|
config := &testcase.Config
|
||||||
for _, step := range testcase.TestSteps {
|
for _, step := range testcase.TestSteps {
|
||||||
if err := step.Run(); err != nil {
|
if err := step.Run(config); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
5
step.go
5
step.go
@@ -15,6 +15,7 @@ func Step(name string) *step {
|
|||||||
|
|
||||||
type step struct {
|
type step struct {
|
||||||
runner *Runner
|
runner *Runner
|
||||||
|
config *TConfig
|
||||||
*TStep
|
*TStep
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -188,7 +189,7 @@ func (s *requestWithOptionalArgs) Type() string {
|
|||||||
return fmt.Sprintf("request-%v", s.step.Request.Method)
|
return fmt.Sprintf("request-%v", s.step.Request.Method)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *requestWithOptionalArgs) Run() error {
|
func (s *requestWithOptionalArgs) Run(config *TConfig) error {
|
||||||
return s.runner.runStep(s.step)
|
return s.runner.runStep(s.step)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -216,6 +217,6 @@ func (s *testcaseWithOptionalArgs) Type() string {
|
|||||||
return "testcase"
|
return "testcase"
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *testcaseWithOptionalArgs) Run() error {
|
func (s *testcaseWithOptionalArgs) Run(config *TConfig) error {
|
||||||
return s.runner.runCase(s.step.TestCase)
|
return s.runner.runCase(s.step.TestCase)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -70,10 +70,11 @@ func TestRunRequestPostDataToStruct(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestRunRequestRun(t *testing.T) {
|
func TestRunRequestRun(t *testing.T) {
|
||||||
if err := stepGET.Run(); err != nil {
|
config := &TConfig{}
|
||||||
|
if err := stepGET.Run(config); err != nil {
|
||||||
t.Fatalf("tStep.Run() error: %s", err)
|
t.Fatalf("tStep.Run() error: %s", err)
|
||||||
}
|
}
|
||||||
if err := stepPOSTData.Run(); err != nil {
|
if err := stepPOSTData.Run(config); err != nil {
|
||||||
t.Fatalf("tStepPOSTData.Run() error: %s", err)
|
t.Fatalf("tStepPOSTData.Run() error: %s", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,6 +27,6 @@ func (s *stepRequestValidation) Type() string {
|
|||||||
return fmt.Sprintf("request-%v", s.step.Request.Method)
|
return fmt.Sprintf("request-%v", s.step.Request.Method)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *stepRequestValidation) Run() error {
|
func (s *stepRequestValidation) Run(config *TConfig) error {
|
||||||
return s.runner.runStep(s.step)
|
return s.runner.runStep(s.step)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user