forked from ozontech/allure-go
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request ozontech#31 from ozontech/release/issue-30
Release/issue 30
- Loading branch information
Showing
11 changed files
with
264 additions
and
14 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
//go:build examples_new | ||
// +build examples_new | ||
|
||
package suite_demo | ||
|
||
import ( | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
//go:build examples_new | ||
// +build examples_new | ||
|
||
package suite_demo | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/jackc/fake" | ||
"github.com/ozontech/allure-go/pkg/allure" | ||
"github.com/ozontech/allure-go/pkg/framework/provider" | ||
"github.com/ozontech/allure-go/pkg/framework/suite" | ||
) | ||
|
||
type Example struct { | ||
country string | ||
number int | ||
} | ||
|
||
func (e *Example) String() string { | ||
return fmt.Sprintf("%s#%d", e.country, e.number) | ||
} | ||
|
||
type SetupSuite struct { | ||
suite.Suite | ||
ParamMyTest []*Example | ||
} | ||
|
||
func (s *SetupSuite) BeforeAll(t provider.T) { | ||
for i := 0; i < 10; i++ { | ||
s.ParamMyTest = append(s.ParamMyTest, &Example{ | ||
country: fake.Country(), | ||
number: fake.Year(1900, 2000), | ||
}) | ||
} | ||
} | ||
|
||
func (s *SetupSuite) BeforeEach(t provider.T) { | ||
t.Epic("Demo") | ||
t.Feature("BeforeAfter") | ||
t.Step(allure.NewSimpleStep("This Step will be before Each")) | ||
} | ||
|
||
func (s *SetupSuite) TableTestMyTest(t provider.T, example *Example) { | ||
t.Titlef("TableTest With Setup - %s", example) | ||
t.Descriptionf(` | ||
Test will unpack all data from passed parameter to the variables in WithTestSetup func. | ||
After test finish, it will do ctx.Done() in TestTearDown. | ||
All Setup and TearDown tests will be add as Befores and Afters to test's container. | ||
Used Data: %s`, example) | ||
t.Tags("Parametrized", "Parallel", "Setup", "BeforeAfter") | ||
|
||
t.Parallel() | ||
var ( | ||
country string | ||
year int | ||
ctx context.Context | ||
) | ||
t.WithTestSetup(func(t provider.T) { | ||
t.WithNewStep("init country", func(sCtx provider.StepCtx) { | ||
country = example.country | ||
sCtx.WithNewParameters("country", country) | ||
}) | ||
t.WithNewStep("init year", func(sCtx provider.StepCtx) { | ||
year = example.number | ||
sCtx.WithNewParameters("year", year) | ||
}) | ||
t.WithNewStep("init ctx", func(sCtx provider.StepCtx) { | ||
ctx = context.Background() | ||
sCtx.WithNewParameters("ctx", ctx) | ||
}) | ||
}) | ||
|
||
t.Require().NotEqual("PonyCountry", country, "No magic countries in the list") | ||
t.Require().NotEqual(2007, year, "No one returned to 2007") | ||
t.Require().NotNil(ctx, "Not empty context") | ||
|
||
defer t.WithTestTeardown(func(t provider.T) { | ||
t.WithNewStep("Close ctx", func(sCtx provider.StepCtx) { | ||
ctx.Done() | ||
sCtx.WithNewParameters("ctx", ctx) | ||
}) | ||
}) | ||
} | ||
|
||
func (s *SetupSuite) TestMyOtherTest(t provider.T) { | ||
t.Title("Just Test WithSetup") | ||
t.Description(` | ||
Test will prepare some data at TestSetup.`) | ||
t.Tags("Parallel", "Setup", "BeforeAfter") | ||
|
||
t.Parallel() | ||
var ( | ||
name string | ||
age int | ||
) | ||
|
||
t.WithTestSetup(func(t provider.T) { | ||
t.WithNewStep("init args", func(sCtx provider.StepCtx) { | ||
name = fake.FullName() | ||
age = fake.Day() | ||
sCtx.WithNewParameters("name", name, "age", age) | ||
}) | ||
}) | ||
} | ||
|
||
func TestRunner(t *testing.T) { | ||
suite.RunSuite(t, new(SetupSuite)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,35 @@ | ||
package manager | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/ozontech/allure-go/pkg/allure" | ||
) | ||
|
||
// Title changes default test name to title(string) | ||
func (a *allureManager) Title(title string) { | ||
// Title changes default test name to title(using fmt.Sprint) | ||
func (a *allureManager) Title(args ...interface{}) { | ||
a.safely(func(result *allure.Result) { | ||
result.Name = fmt.Sprint(args...) | ||
}) | ||
} | ||
|
||
// Titlef changes default test name to title(using fmt.Sprintf) | ||
func (a *allureManager) Titlef(format string, args ...interface{}) { | ||
a.safely(func(result *allure.Result) { | ||
result.Name = fmt.Sprintf(format, args...) | ||
}) | ||
} | ||
|
||
// Description provides description to test result(using fmt.Sprint) | ||
func (a *allureManager) Description(args ...interface{}) { | ||
a.safely(func(result *allure.Result) { | ||
result.Name = title | ||
result.Description = fmt.Sprint(args...) | ||
}) | ||
} | ||
|
||
// Description provides description to test result | ||
func (a *allureManager) Description(description string) { | ||
// Descriptionf provides description to test result(using fmt.Sprintf) | ||
func (a *allureManager) Descriptionf(format string, args ...interface{}) { | ||
a.safely(func(result *allure.Result) { | ||
result.Description = description | ||
result.Description = fmt.Sprintf(format, args...) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters