Skip to content

Commit

Permalink
Add ability to Skip a step (#16)
Browse files Browse the repository at this point in the history
  • Loading branch information
MaximeBellou authored Dec 3, 2019
1 parent f29bdf4 commit e43f064
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 10 deletions.
5 changes: 3 additions & 2 deletions example/example_parameters_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ package example

import (
"fmt"
"testing"

"github.com/dailymotion/allure-go"
"github.com/dailymotion/allure-go/severity"
"testing"
)

type SampleObject struct {
Expand Down Expand Up @@ -56,7 +57,7 @@ func TestAllureStepWithParameters(t *testing.T) {
for i := 0; i < 5; i++ {
allure.StepWithParameter("Step with parameters", map[string]interface{}{"counter": i}, func() {})
}

allure.SkipStepWithParameter("Step with parameters", "Skip this step with parameters", map[string]interface{}{"counter": 6}, func() {})
})
}

Expand Down
1 change: 1 addition & 0 deletions example/example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ func TestWithIntricateSubsteps(t *testing.T) {
t.Errorf("Failure")
})
allure.Step("Sub-step 1.2", func() {})
allure.SkipStep("Sub-step 1.3", "Skip this step because of defect to be fixed", func() {})
})
allure.Step("Step 2", func() {
allure.Step("Sub-step 2.1", func() {
Expand Down
43 changes: 35 additions & 8 deletions step.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@ import (
)

type stepObject struct {
Name string `json:"name,omitempty"`
Status string `json:"status,omitempty"`
Stage string `json:"stage"`
ChildrenSteps []stepObject `json:"steps"`
Attachments []attachment `json:"attachments"`
Parameters []Parameter `json:"parameters"`
Start int64 `json:"start"`
Stop int64 `json:"stop"`
Name string `json:"name,omitempty"`
Status string `json:"status,omitempty"`
StatusDetail statusDetails `json:"statusDetails,omitempty"`
Stage string `json:"stage"`
ChildrenSteps []stepObject `json:"steps"`
Attachments []attachment `json:"attachments"`
Parameters []Parameter `json:"parameters"`
Start int64 `json:"start"`
Stop int64 `json:"stop"`
}

func (s *stepObject) GetSteps() []stepObject {
Expand All @@ -39,6 +40,12 @@ func Step(description string, action func()) {
StepWithParameter(description, nil, action)
}

// SkipStep doesn't execute the action and marks the step as skipped in report
// Reason won't appear in report until https://github.com/allure-framework/allure2/issues/774 is fixed
func SkipStep(description, reason string, action func()) {
SkipStepWithParameter(description, reason, nil, action)
}

// StepWithParameter is meant to be wrapped around actions with the purpose of logging the parameters
func StepWithParameter(description string, parameters map[string]interface{}, action func()) {
step := newStep()
Expand Down Expand Up @@ -69,6 +76,26 @@ func StepWithParameter(description string, parameters map[string]interface{}, ac
step.Status = "passed"
}

// SkipStepWithParameter doesn't execute the action and marks the step as skipped in report
// Reason won't appear in report until https://github.com/allure-framework/allure2/issues/774 is fixed
func SkipStepWithParameter(description, reason string, parameters map[string]interface{}, action func()) {
step := newStep()
step.Start = getTimestampMs()
step.Name = description
if parameters == nil || len(parameters) > 0 {
step.Parameters = convertMapToParameters(parameters)
}
step.Status = "skipped"
step.StatusDetail.Message = reason
if currentStepObj, ok := ctxMgr.GetValue(nodeKey); ok {
currentStep := currentStepObj.(hasSteps)
currentStep.AddStep(*step)
} else {
log.Fatalln("could not retrieve current allure node")
}
step.Stop = getTimestampMs()
}

func newStep() *stepObject {
return &stepObject{
Attachments: make([]attachment, 0),
Expand Down

0 comments on commit e43f064

Please sign in to comment.