Skip to content

Commit

Permalink
Merge pull request #106 from ozontech/release/issue-105
Browse files Browse the repository at this point in the history
add StatusDetails field to steps
  • Loading branch information
koodeex authored Jan 20, 2025
2 parents c142409 + ead3005 commit 2c070ab
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 11 deletions.
29 changes: 20 additions & 9 deletions pkg/allure/step.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
package allure

type Step struct {
Name string `json:"name,omitempty"`
Status Status `json:"status,omitempty"`
Attachments []*Attachment `json:"attachments,omitempty"`
Start int64 `json:"start,omitempty"`
Stop int64 `json:"stop,omitempty"`
Steps []*Step `json:"steps,omitempty"`
Parameters []*Parameter `json:"parameters,omitempty"`
parent *Step
Name string `json:"name,omitempty"`
Status Status `json:"status,omitempty"`
StatusDetails StatusDetail `json:"statusDetails"`
Attachments []*Attachment `json:"attachments,omitempty"`
Start int64 `json:"start,omitempty"`
Stop int64 `json:"stop,omitempty"`
Steps []*Step `json:"steps,omitempty"`
Parameters []*Parameter `json:"parameters,omitempty"`
parent *Step
}

// NewStep Constructor. Creates a new `allure.Step` object with field values passed in arguments
Expand All @@ -24,7 +25,7 @@ func NewStep(name string, status Status, start int64, stop int64, parameters []*
}

// NewSimpleStep Constructor. Creates a `Step` object, by calling `allure.NewStep` with certain standard values
//(except for the Step name and possible parameters)
// (except for the Step name and possible parameters)
// =================================
// | Field Value| Default |
// =================================
Expand Down Expand Up @@ -66,6 +67,16 @@ func (s *Step) WithNewParameters(kv ...interface{}) *Step {
return s
}

// WithStatusDetails accept error message and trace.
// Returns pointer to the current Step (for Fluent Interface).
func (s *Step) WithStatusDetails(message string, trace string) *Step {
s.StatusDetails = StatusDetail{
Message: message,
Trace: trace,
}
return s
}

// Passed Puts `Step.Status` = `passed`.
// Returns a pointer to the current Step (for Fluent Interface).
func (s *Step) Passed() *Step {
Expand Down
39 changes: 37 additions & 2 deletions pkg/framework/core/common/step_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,14 +94,14 @@ func (ctx *stepCtx) FailNow() {
func (ctx *stepCtx) Error(args ...interface{}) {
ctx.t.GetRealT().Helper()

ctx.Fail()
ctx.FailWithMessage(fmt.Sprintln(args...))
ctx.t.Error(args...)
}

func (ctx *stepCtx) Errorf(format string, args ...interface{}) {
ctx.t.GetRealT().Helper()

ctx.Fail()
ctx.FailWithMessage(format, args...)
ctx.t.Errorf(format, args...)
}

Expand All @@ -117,6 +117,10 @@ func (ctx *stepCtx) Logf(format string, args ...interface{}) {
ctx.t.Logf(format, args...)
}

func (ctx *stepCtx) WithStatusDetails(message, trace string) {
ctx.currentStep.WithStatusDetails(message, trace)
}

func (ctx *stepCtx) CurrentStep() *allure.Step {
return ctx.currentStep
}
Expand Down Expand Up @@ -169,6 +173,7 @@ func (ctx *stepCtx) WithNewStep(stepName string, step func(ctx provider.StepCtx)
ctxName := newCtx.ExecutionContextName()
errMsg := fmt.Sprintf("%s panicked: %v\n%s", ctxName, r, debug.Stack())
newCtx.Broken()
newCtx.WithStatusDetails(fmt.Sprintf("%s panicked", ctxName), errMsg)
TestError(ctx.t, ctx.p, ctxName, errMsg)
}
}()
Expand Down Expand Up @@ -212,6 +217,36 @@ func (ctx *stepCtx) BrokenNow() {
ctx.t.BrokenNow()
}

func (ctx *stepCtx) BrokenNowWithMessage(format string, args ...interface{}) {
errMsg := fmt.Sprintf(format, args...)
short := errMsg
if len(errMsg) > 100 {
short = short[:100]
}
ctx.WithStatusDetails(short, errMsg)
ctx.BrokenNow()
}

func (ctx *stepCtx) FailWithMessage(format string, args ...interface{}) {
errMsg := fmt.Sprintf(format, args...)
short := errMsg
if len(errMsg) > 100 {
short = short[:100]
}
ctx.WithStatusDetails(short, errMsg)
ctx.Fail()
}

func (ctx *stepCtx) BrokenWithMessage(format string, args ...interface{}) {
errMsg := fmt.Sprintf(format, args...)
short := errMsg
if len(errMsg) > 100 {
short = short[:100]
}
ctx.WithStatusDetails(short, errMsg)
ctx.Broken()
}

func (ctx *stepCtx) Break(args ...interface{}) {
ctx.Broken()
ctx.t.Break(args...)
Expand Down
1 change: 1 addition & 0 deletions pkg/framework/provider/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ type StepCtx interface {

LogStep(args ...interface{})
LogfStep(format string, args ...interface{})
WithStatusDetails(message, trace string)
CurrentStep() *allure.Step

Broken()
Expand Down

0 comments on commit 2c070ab

Please sign in to comment.