Skip to content

Commit

Permalink
Merge pull request #38 from dailymotion/retries_and_suites
Browse files Browse the repository at this point in the history
Retried test deduplication and suites feature
  • Loading branch information
ubermensch01 authored Jan 14, 2022
2 parents c1bc798 + e5483d7 commit 7992366
Show file tree
Hide file tree
Showing 5 changed files with 100 additions and 8 deletions.
52 changes: 52 additions & 0 deletions example/example_suite_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package example

import (
"testing"

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

func TestSuiteExample(t *testing.T) {
allure.Test(t,
allure.ParentSuite("Epic Root Suite"),
allure.Suite("Test Suite"),
allure.SubSuite("Sub Suite Example"),
allure.Description("This is a test to show allure implementation with a passing test"),
allure.Action(func() {
s := "Hello world"
if len(s) == 0 {
t.Errorf("Expected 'hello world' string, but got %s ", s)
}
}))
}

func TestSuiteWithIntricateSubsteps(t *testing.T) {
allure.Test(t,
allure.ParentSuite("Epic Root Suite"),
allure.Suite("Test Suite"),
allure.SubSuite("Sub Suite Example"),
allure.Description("Test"),
allure.Action(func() {
allure.Step(allure.Description("Step 1"), allure.Action(func() {
doSomething()
allure.Step(allure.Description("Sub-step 1.1"), allure.Action(func() {
t.Errorf("Failure")
}))
allure.Step(allure.Description("Sub-step 1.2"), allure.Action(func() {}))
allure.SkipStep(allure.Description("Sub-step 1.3"), allure.Reason("Skip this step because of defect to be fixed"), allure.Action(func() {}))
}))
allure.Step(allure.Description("Step 2"), allure.Action(func() {
allure.Step(allure.Description("Sub-step 2.1"), allure.Action(func() {
allure.Step(allure.Description("Step 2.1.1"), allure.Action(func() {
allure.Step(allure.Description("Sub-step 2.1.1.1"), allure.Action(func() {
t.Errorf("Failure")
}))
allure.Step(allure.Description("Sub-step 2.1.1.2"), allure.Action(func() {
t.Error("Failed like this")
}))
}))
}))
allure.Step(allure.Description("Sub-step 2.2"), allure.Action(func() {}))
}))
}))
}
18 changes: 18 additions & 0 deletions options.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,21 @@ func Name(name string) Option {
r.addName(name)
}
}

func Suite(suite string) Option {
return func(r hasOptions) {
r.addLabel("suite", suite)
}
}

func SubSuite(subSuite string) Option {
return func(r hasOptions) {
r.addLabel("subSuite", subSuite)
}
}

func ParentSuite(parentSuite string) Option {
return func(r hasOptions) {
r.addLabel("parentSuite", parentSuite)
}
}
8 changes: 4 additions & 4 deletions result.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,20 @@ package allure
import (
"encoding/json"
"fmt"
"github.com/pkg/errors"
"io/ioutil"
"os"
"runtime"
"strings"
"testing"

"github.com/pkg/errors"
)

//result is the top level report object for a test
type result struct {
UUID string `json:"uuid,omitempty"`
TestCaseID string `json:"testCaseId,omitempty"`
HistoryID string `json:"historyId,omitempty"`
Name string `json:"name,omitempty"`
Description string `json:"description,omitempty"`
Status string `json:"status,omitempty"`
Expand Down Expand Up @@ -128,9 +131,6 @@ func (r *result) setDefaultLabels(t *testing.T) {

//TODO: these labels are available, but should be handled separately.

// ParentSuite string
// Suite string
// SubSuite string
// Thread string
// Framework string
}
Expand Down
3 changes: 2 additions & 1 deletion step.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package allure

import (
"github.com/pkg/errors"
"log"
"testing"

"github.com/pkg/errors"

"github.com/jtolds/gls"
)

Expand Down
27 changes: 24 additions & 3 deletions test.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
package allure

import (
"crypto/sha256"
"fmt"
"github.com/dailymotion/allure-go/severity"
"github.com/fatih/camelcase"
"github.com/jtolds/gls"
"log"
"runtime/debug"
"strings"
"testing"

"github.com/dailymotion/allure-go/severity"
"github.com/fatih/camelcase"
"github.com/jtolds/gls"
)

type testLabels struct {
Expand Down Expand Up @@ -40,6 +42,10 @@ func SkipTest(t *testing.T, testOptions ...Option) {
option(r)
}

currentHash := getSha256(r.Labels, r.FullName)
r.TestCaseID = currentHash
r.HistoryID = currentHash

getCurrentTestPhaseObject(t).Test = r
r.Stop = getTimestampMs()
r.Stage = "finished"
Expand Down Expand Up @@ -83,6 +89,10 @@ func Test(t *testing.T, testOptions ...Option) {
r.Test = func() {}
}

currentHash := getSha256(r.Labels, r.FullName)
r.TestCaseID = currentHash
r.HistoryID = currentHash

defer func() {
panicObject := recover()
getCurrentTestPhaseObject(t).Test = r
Expand Down Expand Up @@ -126,3 +136,14 @@ func Test(t *testing.T, testOptions ...Option) {
testInstanceKey: t,
}, r.Test)
}

func getSha256(labels []label, name string) string {
hash := sha256.New()

hash.Write([]byte(fmt.Sprintf("%v", struct {
Labels []label
Name string
}{labels, name})))

return fmt.Sprintf("%x", hash.Sum(nil))
}

0 comments on commit 7992366

Please sign in to comment.