mirror of
https://github.com/httprunner/httprunner.git
synced 2026-07-08 21:51:43 +08:00
feat: log transaction when running tests
This commit is contained in:
@@ -116,6 +116,10 @@ func (tc *TCase) ToTestCase() (*TestCase, error) {
|
|||||||
testCase.TestSteps = append(testCase.TestSteps, &stepTestCaseWithOptionalArgs{
|
testCase.TestSteps = append(testCase.TestSteps, &stepTestCaseWithOptionalArgs{
|
||||||
step: step,
|
step: step,
|
||||||
})
|
})
|
||||||
|
} else if step.Transaction != nil {
|
||||||
|
testCase.TestSteps = append(testCase.TestSteps, &stepTransaction{
|
||||||
|
step: step,
|
||||||
|
})
|
||||||
} else {
|
} else {
|
||||||
log.Warn().Interface("step", step).Msg("[convertTestCase] unexpected step")
|
log.Warn().Interface("step", step).Msg("[convertTestCase] unexpected step")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,3 +1,3 @@
|
|||||||
package version
|
package version
|
||||||
|
|
||||||
const VERSION = "v0.2.2"
|
const VERSION = "v0.3.0"
|
||||||
|
|||||||
@@ -50,6 +50,7 @@ type TStep struct {
|
|||||||
Name string `json:"name" yaml:"name"` // required
|
Name string `json:"name" yaml:"name"` // required
|
||||||
Request *Request `json:"request,omitempty" yaml:"request,omitempty"`
|
Request *Request `json:"request,omitempty" yaml:"request,omitempty"`
|
||||||
TestCase *TestCase `json:"testcase,omitempty" yaml:"testcase,omitempty"`
|
TestCase *TestCase `json:"testcase,omitempty" yaml:"testcase,omitempty"`
|
||||||
|
Transaction *Transaction `json:"transaction,omitempty" yaml:"transaction,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"`
|
||||||
@@ -58,6 +59,11 @@ type TStep struct {
|
|||||||
Export []string `json:"export,omitempty" yaml:"export,omitempty"`
|
Export []string `json:"export,omitempty" yaml:"export,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type Transaction struct {
|
||||||
|
Name string `json:"name" yaml:"name"`
|
||||||
|
Type string `json:"type" yaml:"type"` // start/end
|
||||||
|
}
|
||||||
|
|
||||||
// TCase represents testcase data structure.
|
// TCase represents testcase data structure.
|
||||||
// Each testcase includes one public config and several sequential teststeps.
|
// Each testcase includes one public config and several sequential teststeps.
|
||||||
type TCase struct {
|
type TCase struct {
|
||||||
|
|||||||
10
runner.go
10
runner.go
@@ -118,6 +118,16 @@ func (r *hrpRunner) runCase(testcase *TestCase) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (r *hrpRunner) runStep(step IStep, config *TConfig) (stepResult *stepData, err error) {
|
func (r *hrpRunner) runStep(step IStep, config *TConfig) (stepResult *stepData, err error) {
|
||||||
|
// step type priority order: transaction > testcase > request
|
||||||
|
if stepTransaction, ok := step.(*stepTransaction); ok {
|
||||||
|
// transaction
|
||||||
|
log.Info().
|
||||||
|
Str("name", stepTransaction.step.Transaction.Name).
|
||||||
|
Str("type", stepTransaction.step.Transaction.Type).
|
||||||
|
Msg("transaction")
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
|
||||||
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
|
||||||
|
|||||||
20
step.go
20
step.go
@@ -277,3 +277,23 @@ func (s *stepTestCaseWithOptionalArgs) Type() string {
|
|||||||
func (s *stepTestCaseWithOptionalArgs) ToStruct() *TStep {
|
func (s *stepTestCaseWithOptionalArgs) ToStruct() *TStep {
|
||||||
return s.step
|
return s.step
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// implements IStep interface
|
||||||
|
type stepTransaction struct {
|
||||||
|
step *TStep
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *stepTransaction) Name() string {
|
||||||
|
if s.step.Name != "" {
|
||||||
|
return s.step.Name
|
||||||
|
}
|
||||||
|
return fmt.Sprintf("transaction %s %s", s.step.Transaction.Name, s.step.Transaction.Type)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *stepTransaction) Type() string {
|
||||||
|
return "transaction"
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *stepTransaction) ToStruct() *TStep {
|
||||||
|
return s.step
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user