Skip to content
This repository has been archived by the owner on Mar 28, 2022. It is now read-only.

Commit

Permalink
refactor: NewStep
Browse files Browse the repository at this point in the history
  • Loading branch information
debugtalk committed Dec 8, 2021
1 parent 9997206 commit a301266
Show file tree
Hide file tree
Showing 6 changed files with 110 additions and 102 deletions.
8 changes: 4 additions & 4 deletions convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,19 +109,19 @@ func (tc *TCase) ToTestCase() (*TestCase, error) {
}
for _, step := range tc.TestSteps {
if step.Request != nil {
testCase.TestSteps = append(testCase.TestSteps, &stepRequestWithOptionalArgs{
testCase.TestSteps = append(testCase.TestSteps, &StepRequestWithOptionalArgs{
step: step,
})
} else if step.TestCase != nil {
testCase.TestSteps = append(testCase.TestSteps, &stepTestCaseWithOptionalArgs{
testCase.TestSteps = append(testCase.TestSteps, &StepTestCaseWithOptionalArgs{
step: step,
})
} else if step.Transaction != nil {
testCase.TestSteps = append(testCase.TestSteps, &stepTransaction{
testCase.TestSteps = append(testCase.TestSteps, &StepTransaction{
step: step,
})
} else if step.Rendezvous != nil {
testCase.TestSteps = append(testCase.TestSteps, &stepRendezvous{
testCase.TestSteps = append(testCase.TestSteps, &StepRendezvous{
step: step,
})
} else {
Expand Down
16 changes: 8 additions & 8 deletions extract.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,32 @@ package hrp

import "fmt"

// implements IStep interface
type stepRequestExtraction struct {
// StepRequestExtraction implements IStep interface.
type StepRequestExtraction struct {
step *TStep
}

// WithJmesPath sets the JMESPath expression to extract from the response.
func (s *stepRequestExtraction) WithJmesPath(jmesPath string, varName string) *stepRequestExtraction {
func (s *StepRequestExtraction) WithJmesPath(jmesPath string, varName string) *StepRequestExtraction {
s.step.Extract[varName] = jmesPath
return s
}

// Validate switches to step validation.
func (s *stepRequestExtraction) Validate() *stepRequestValidation {
return &stepRequestValidation{
func (s *StepRequestExtraction) Validate() *StepRequestValidation {
return &StepRequestValidation{
step: s.step,
}
}

func (s *stepRequestExtraction) Name() string {
func (s *StepRequestExtraction) Name() string {
return s.step.Name
}

func (s *stepRequestExtraction) Type() string {
func (s *StepRequestExtraction) Type() string {
return fmt.Sprintf("request-%v", s.step.Request.Method)
}

func (s *stepRequestExtraction) ToStruct() *TStep {
func (s *StepRequestExtraction) ToStruct() *TStep {
return s.step
}
5 changes: 3 additions & 2 deletions models.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,8 @@ type ITestCase interface {
ToTCase() (*TCase, error)
}

// TestCase is a container for one testcase.
// used for testcase runner
// TestCase is a container for one testcase, which is used for testcase runner.
// TestCase implements ITestCase interface.
type TestCase struct {
Config IConfig
TestSteps []IStep
Expand All @@ -108,6 +108,7 @@ func (tc *TestCase) ToTestCase() (*TestCase, error) {
return tc, nil
}

// TestCasePath implements ITestCase interface.
type TestCasePath struct {
Path string
}
Expand Down
6 changes: 3 additions & 3 deletions runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,14 +119,14 @@ func (r *hrpRunner) runCase(testcase *TestCase) error {

func (r *hrpRunner) runStep(step IStep, config IConfig) (stepResult *stepData, err error) {
// step type priority order: transaction > rendezvous > testcase > request
if stepTran, ok := step.(*stepTransaction); ok {
if stepTran, ok := step.(*StepTransaction); ok {
// transaction
log.Info().
Str("name", stepTran.step.Transaction.Name).
Str("type", stepTran.step.Transaction.Type).
Msg("transaction")
return nil, nil
} else if stepRend, ok := step.(*stepRendezvous); ok {
} else if stepRend, ok := step.(*StepRendezvous); ok {
// rendezvous
log.Info().
Str("name", stepRend.step.Rendezvous.Name).
Expand Down Expand Up @@ -162,7 +162,7 @@ func (r *hrpRunner) runStep(step IStep, config IConfig) (stepResult *stepData, e
}
copiedStep.Variables = parsedVariables // avoid data racing

if _, ok := step.(*stepTestCaseWithOptionalArgs); ok {
if _, ok := step.(*StepTestCaseWithOptionalArgs); ok {
// run referenced testcase
log.Info().Str("testcase", copiedStep.Name).Msg("run referenced testcase")
// TODO: override testcase config
Expand Down
Loading

0 comments on commit a301266

Please sign in to comment.