feat: log transaction when running tests

This commit is contained in:
debugtalk
2021-12-08 11:12:02 +08:00
parent 6da8ebf62c
commit 01cd071bb9
5 changed files with 41 additions and 1 deletions

View File

@@ -116,6 +116,10 @@ func (tc *TCase) ToTestCase() (*TestCase, error) {
testCase.TestSteps = append(testCase.TestSteps, &stepTestCaseWithOptionalArgs{
step: step,
})
} else if step.Transaction != nil {
testCase.TestSteps = append(testCase.TestSteps, &stepTransaction{
step: step,
})
} else {
log.Warn().Interface("step", step).Msg("[convertTestCase] unexpected step")
}

View File

@@ -1,3 +1,3 @@
package version
const VERSION = "v0.2.2"
const VERSION = "v0.3.0"

View File

@@ -50,6 +50,7 @@ type TStep struct {
Name string `json:"name" yaml:"name"` // required
Request *Request `json:"request,omitempty" yaml:"request,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"`
SetupHooks []string `json:"setup_hooks,omitempty" yaml:"setup_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"`
}
type Transaction struct {
Name string `json:"name" yaml:"name"`
Type string `json:"type" yaml:"type"` // start/end
}
// TCase represents testcase data structure.
// Each testcase includes one public config and several sequential teststeps.
type TCase struct {

View File

@@ -118,6 +118,16 @@ func (r *hrpRunner) runCase(testcase *TestCase) 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")
// copy step to avoid data racing

20
step.go
View File

@@ -277,3 +277,23 @@ func (s *stepTestCaseWithOptionalArgs) Type() string {
func (s *stepTestCaseWithOptionalArgs) ToStruct() *TStep {
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
}