refactor: Run with config

This commit is contained in:
debugtalk
2021-09-22 20:12:33 +08:00
parent a4f9d073c7
commit 3f3b965b47
7 changed files with 13 additions and 10 deletions

View File

@@ -33,9 +33,10 @@ func convertBoomerTask(testcase *TestCase) *boomer.Task {
Name: testcase.Config.Name,
Weight: testcase.Config.Weight,
Fn: func() {
config := &testcase.Config
for _, step := range testcase.TestSteps {
start := time.Now()
err := step.Run()
err := step.Run(config)
elapsed := time.Since(start).Nanoseconds() / int64(time.Millisecond)
if err == nil {

View File

@@ -27,6 +27,6 @@ func (s *stepRequestExtraction) Type() string {
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)
}

View File

@@ -58,7 +58,7 @@ type TStep struct {
type IStep interface {
Name() string
Type() string
Run() error
Run(config *TConfig) error
}
type TestCase struct {

View File

@@ -32,9 +32,9 @@ func (r *Runner) Run(testcases ...*TestCase) error {
}
func (r *Runner) runCase(testcase *TestCase) error {
// config := testcase.Config
config := &testcase.Config
for _, step := range testcase.TestSteps {
if err := step.Run(); err != nil {
if err := step.Run(config); err != nil {
return err
}
}

View File

@@ -15,6 +15,7 @@ func Step(name string) *step {
type step struct {
runner *Runner
config *TConfig
*TStep
}
@@ -188,7 +189,7 @@ func (s *requestWithOptionalArgs) Type() string {
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)
}
@@ -216,6 +217,6 @@ func (s *testcaseWithOptionalArgs) Type() string {
return "testcase"
}
func (s *testcaseWithOptionalArgs) Run() error {
func (s *testcaseWithOptionalArgs) Run(config *TConfig) error {
return s.runner.runCase(s.step.TestCase)
}

View File

@@ -70,10 +70,11 @@ func TestRunRequestPostDataToStruct(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)
}
if err := stepPOSTData.Run(); err != nil {
if err := stepPOSTData.Run(config); err != nil {
t.Fatalf("tStepPOSTData.Run() error: %s", err)
}
}

View File

@@ -27,6 +27,6 @@ func (s *stepRequestValidation) Type() string {
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)
}