Skip to content

Commit

Permalink
Fix linter errors
Browse files Browse the repository at this point in the history
  • Loading branch information
dkx86 committed Jul 3, 2024
1 parent a17210b commit 8009291
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 26 deletions.
31 changes: 16 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ The project started as a fork of testify, but over time it got its own runner an
+ [XSkip](#xskip)
+ [:rocket: Parametrized tests](#parametrized-test)
+ [Setup test](#setup-test)
+ [Prevent loosing allureID in test results](#Prevent-loosing-allureID-in-test-results)

## :zap: Features

Expand Down Expand Up @@ -806,13 +807,13 @@ Allure output:

![](.resources/example_setup_test.png)

### Prevent loosing allureId in test results
### Prevent loosing allureID in test results

When suit fails at the setup stage (beforeAll), report will not contain `allureId` field.
To prevent it you can use `GetAllureId(testName string) string` method for common tests and
When suit fails at the setup stage (beforeAll), report will not contain `ALLURE_ID` field.
To prevent it you can use `GetAllureID(testName string) string` method for common tests and
`InitializeTestsParams()` method for parametrized tests.

**Example for `GetAllureId` method:**
**Example for `GetAllureID` method:**

```go
package suite_demo
Expand All @@ -824,11 +825,11 @@ import (
"github.com/ozontech/allure-go/pkg/framework/suite"
)

type AllureIdSuite struct {
type AllureIDSuite struct {
suite.Suite
}

func (testSuit *AllureIdSuite) GetAllureId(testName string) string {
func (testSuit *AllureIDSuite) GetAllureID(testName string) string {
switch testName {
case "TestWithAllureIDFirst":
return "9001"
Expand All @@ -839,20 +840,20 @@ func (testSuit *AllureIdSuite) GetAllureId(testName string) string {
}
}

func (s *AllureIdSuite) BeforeAll(t provider.T) {
func (s *AllureIDSuite) BeforeAll(t provider.T) {
// code that can fail here
}

func (s *AllureIdSuite) TestWithAllureIDFirst(t provider.T) {
func (s *AllureIDSuite) TestWithAllureIDFirst(t provider.T) {
// code of your test here
}

func (s *AllureIdSuite) TestWithAllureIDSecond(t provider.T) {
func (s *AllureIDSuite) TestWithAllureIDSecond(t provider.T) {
// code of your test here
}

func TestNewDemo(t *testing.T) {
suite.RunSuite(t, new(AllureIdSuite))
suite.RunSuite(t, new(AllureIDSuite))
}

```
Expand All @@ -871,13 +872,13 @@ import (
)

type CitiesParam struct {
allureId string
allureID string
title string
value string
}

func (p CitiesParam) GetAllureId() string {
return p.allureId
func (p CitiesParam) GetAllureID() string {
return p.allureID
}
func (p CitiesParam) GetAllureTitle() string {
return p.title
Expand All @@ -892,13 +893,13 @@ func (s *ParametrizedSuite) InitializeTestsParams() {
s.ParamCities = make([]CitiesParam, 2)
s.ParamCities[0] = CitiesParam{
title: "Title for city test #1",
allureId: "101",
allureID: "101",
value: fake.City(),
}

s.ParamCities[1] = CitiesParam{
title: "Title for city test #2",
allureId: "102",
allureID: "102",
value: fake.City(),
}
}
Expand Down
10 changes: 5 additions & 5 deletions pkg/framework/runner/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ type AllureAfterSuite interface {
AfterAll(t provider.T)
}

// AllureIdSuite has a GetAllureId method,
// which will produce allureIds for the test by its name
type AllureIdSuite interface {
GetAllureId(testName string) string
// AllureIDSuite has a GetAllureID method,
// which will produce allureIDs for the test by its name
type AllureIDSuite interface {
GetAllureID(testName string) string
}

// ParametrizedSuite suit can initialize parameters for
Expand All @@ -47,7 +47,7 @@ type ParametrizedSuite interface {
// ParametrizedTestParam parameter for parametrized test
// with custom AllureId and Title
type ParametrizedTestParam interface {
GetAllureId() string
GetAllureID() string
GetAllureTitle() string
}

Expand Down
12 changes: 6 additions & 6 deletions pkg/framework/runner/suite_runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,11 @@ func collectTests(runner *suiteRunner, tSuite TestSuite) {
packageName = runner.packageName
suiteName = runner.internalT.GetProvider().GetSuiteMeta().GetSuiteName()
suiteFullName = runner.internalT.GetProvider().GetSuiteMeta().GetSuiteFullName()
getAllureId func(string) string
getAllureID func(string) string
)

if ais, ok := tSuite.(AllureIdSuite); ok {
getAllureId = ais.GetAllureId
if ais, ok := tSuite.(AllureIDSuite); ok {
getAllureID = ais.GetAllureID
}

for i := 0; i < methodFinder.NumMethod(); i++ {
Expand All @@ -97,8 +97,8 @@ func collectTests(runner *suiteRunner, tSuite TestSuite) {

testMeta := adapter.NewTestMeta(suiteFullName, suiteName, method.Name, packageName)

if getAllureId != nil {
id := getAllureId(method.Name)
if getAllureID != nil {
id := getAllureID(method.Name)
if len(id) > 0 {
testMeta.GetResult().AddLabel(allure.IDAllureLabel(id))
}
Expand Down Expand Up @@ -196,7 +196,7 @@ func getParamTests(parentTest Test, params map[string]interface{}) map[string]Te

if ptp, ok := param.(ParametrizedTestParam); ok {
meta.GetResult().Name = ptp.GetAllureTitle()
meta.GetResult().AddLabel(allure.IDAllureLabel(ptp.GetAllureId()))
meta.GetResult().AddLabel(allure.IDAllureLabel(ptp.GetAllureID()))
}

res[pName] = &testMethod{
Expand Down

0 comments on commit 8009291

Please sign in to comment.