refactor: replace hardcoded log messages with constants for improved readability and maintainability

This commit is contained in:
lilong.129
2025-06-19 10:43:59 +08:00
parent d7ea86e23d
commit c568be5dc2
3 changed files with 11 additions and 6 deletions

View File

@@ -1 +1 @@
v5.0.0-beta-2506191040
v5.0.0-beta-2506191048

View File

@@ -185,7 +185,7 @@ func (g *HTMLReportGenerator) getStepLogs(stepName string, startTime int64, elap
// Simple approach: use step start/end markers for precise boundaries
for _, logEntry := range g.LogData {
// Check for step boundaries to control inclusion
if logEntry.Message == "run step start" {
if logEntry.Message == RUN_STEP_START {
if stepFieldValue, exists := logEntry.Fields["step"]; exists {
if stepFieldValue == stepName {
inCurrentStep = true
@@ -198,7 +198,7 @@ func (g *HTMLReportGenerator) getStepLogs(stepName string, startTime int64, elap
}
}
if logEntry.Message == "run step end" {
if logEntry.Message == RUN_STEP_END {
if stepFieldValue, exists := logEntry.Fields["step"]; exists {
if stepFieldValue == stepName {
stepLogs = append(stepLogs, logEntry)

View File

@@ -729,6 +729,11 @@ func (r *SessionRunner) Start(givenVars map[string]interface{}) (summary *TestCa
return summary, nil
}
const (
RUN_STEP_START = "run step start"
RUN_STEP_END = "run step end"
)
func (r *SessionRunner) RunStep(step IStep) (stepResult *StepResult, err error) {
// check for interrupt signal before running step
select {
@@ -748,7 +753,7 @@ func (r *SessionRunner) RunStep(step IStep) (stepResult *StepResult, err error)
stepName := step.Name()
stepType := string(step.Type())
log.Info().Str("step", stepName).Str("type", stepType).Msg("run step start")
log.Info().Str("step", stepName).Str("type", stepType).Msg(RUN_STEP_START)
// run times of step
loopTimes := step.Config().Loops
@@ -785,7 +790,7 @@ func (r *SessionRunner) RunStep(step IStep) (stepResult *StepResult, err error)
Bool("success", true).
Int64("elapsed(ms)", stepResult.Elapsed).
Interface("exportVars", stepResult.ExportVars).
Msg("run step end")
Msg(RUN_STEP_END)
continue
}
// run step failed
@@ -793,7 +798,7 @@ func (r *SessionRunner) RunStep(step IStep) (stepResult *StepResult, err error)
Str("type", stepType).
Bool("success", false).
Int64("elapsed(ms)", stepResult.Elapsed).
Msg("run step end")
Msg(RUN_STEP_END)
return stepResult, err
}