Skip to content

Commit

Permalink
Merge pull request #37 from ozontech/release/issue-29
Browse files Browse the repository at this point in the history
Release/issue 29
  • Loading branch information
koodeex authored Sep 2, 2022
2 parents 32923b6 + 34e4fe7 commit dea35d2
Show file tree
Hide file tree
Showing 30 changed files with 288 additions and 230 deletions.
Binary file modified .resources/example_table_test.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions examples/suite_demo/running_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ func (s *TestRunningDemoSuite) TestLabels(t provider.T) {
s.RunSuite(t, new(LabelsDemoSuite))
}

func (s *TestRunningDemoSuite) TestParametrized(t provider.T) {
t.Parallel()
s.RunSuite(t, new(ParametrizedSuite))
}

func TestRunDemo(t *testing.T) {
// use RunSuite to run suite of suites
t.Parallel()
Expand Down
18 changes: 15 additions & 3 deletions examples/suite_demo/setup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,30 @@ type SetupSuite struct {
}

func (s *SetupSuite) BeforeAll(t provider.T) {
var params []*allure.Parameter
for i := 0; i < 10; i++ {
s.ParamMyTest = append(s.ParamMyTest, &Example{
param := &Example{
country: fake.Country(),
number: fake.Year(1900, 2000),
})
}
params = append(params, allure.NewParameter(fmt.Sprintf("Ex %d", i), param))
s.ParamMyTest = append(s.ParamMyTest, param)
}
t.NewStep("BeforeAllStep", params...)
}

func (s *SetupSuite) BeforeEach(t provider.T) {
t.Epic("Demo")
t.Feature("BeforeAfter")
t.Step(allure.NewSimpleStep("This Step will be before Each"))
t.NewStep("This Step will be before Each")
}

func (s *SetupSuite) AfterEach(t provider.T) {
t.NewStep("AfterEach Step")
}

func (s *SetupSuite) AfterAll(t provider.T) {
t.NewStep("AfterAll Step")
}

func (s *SetupSuite) TableTestMyTest(t provider.T, example *Example) {
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ replace (

require (
github.com/jackc/fake v0.0.0-20150926172116-812a484cc733
github.com/ozontech/allure-go/pkg/allure v0.6.3
github.com/ozontech/allure-go/pkg/framework v0.6.17
github.com/ozontech/allure-go/pkg/allure v0.6.4
github.com/ozontech/allure-go/pkg/framework v0.6.18
)

require (
Expand Down
42 changes: 21 additions & 21 deletions pkg/allure/label.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ type Label struct {
}

// NewLabel - builds and returns a new allure.Label. The label key depends on the passed LabelType.
func NewLabel(labelType LabelType, value string) Label {
return Label{
func NewLabel(labelType LabelType, value string) *Label {
return &Label{
Name: labelType.ToString(),
Value: value,
}
Expand Down Expand Up @@ -59,95 +59,95 @@ func (s SeverityType) ToString() string {
}

// LanguageLabel returns Language Label
func LanguageLabel(language string) Label {
func LanguageLabel(language string) *Label {
return NewLabel(Language, language)
}

// FrameWorkLabel returns Framework Label
func FrameWorkLabel(framework string) Label {
func FrameWorkLabel(framework string) *Label {
return NewLabel(Framework, framework)
}

// IDLabel returns ID Label
func IDLabel(testID string) Label {
func IDLabel(testID string) *Label {
return NewLabel(ID, testID)
}

// TagLabel returns Tag Label
func TagLabel(tag string) Label {
func TagLabel(tag string) *Label {
return NewLabel(Tag, tag)
}

// TagLabels returns array of Tag Label
func TagLabels(tags ...string) []Label {
var result []Label
func TagLabels(tags ...string) []*Label {
var result []*Label
for _, tag := range tags {
result = append(result, TagLabel(tag))
}
return result
}

// HostLabel returns Host Label
func HostLabel(host string) Label {
func HostLabel(host string) *Label {
return NewLabel(Host, host)
}

// ThreadLabel returns Thread Label
func ThreadLabel(thread string) Label {
func ThreadLabel(thread string) *Label {
return NewLabel(Thread, thread)
}

// SeverityLabel returns Severity Label
func SeverityLabel(severity SeverityType) Label {
func SeverityLabel(severity SeverityType) *Label {
return NewLabel(Severity, severity.ToString())
}

// SubSuiteLabel returns SubSuite Label
func SubSuiteLabel(subSuite string) Label {
func SubSuiteLabel(subSuite string) *Label {
return NewLabel(SubSuite, subSuite)
}

// EpicLabel returns Epic Label
func EpicLabel(epic string) Label {
func EpicLabel(epic string) *Label {
return NewLabel(Epic, epic)
}

// StoryLabel returns Story Label
func StoryLabel(story string) Label {
func StoryLabel(story string) *Label {
return NewLabel(Story, story)
}

// FeatureLabel returns Feature Label
func FeatureLabel(feature string) Label {
func FeatureLabel(feature string) *Label {
return NewLabel(Feature, feature)
}

// ParentSuiteLabel returns ParentSuite Label
func ParentSuiteLabel(parent string) Label {
func ParentSuiteLabel(parent string) *Label {
return NewLabel(ParentSuite, parent)
}

// SuiteLabel returns Suite Label
func SuiteLabel(suite string) Label {
func SuiteLabel(suite string) *Label {
return NewLabel(Suite, suite)
}

// PackageLabel returns Package Label
func PackageLabel(packageName string) Label {
func PackageLabel(packageName string) *Label {
return NewLabel(Package, packageName)
}

// OwnerLabel returns Owner Label
func OwnerLabel(ownerName string) Label {
func OwnerLabel(ownerName string) *Label {
return NewLabel(Owner, ownerName)
}

// LeadLabel returns Lead Label
func LeadLabel(leadName string) Label {
func LeadLabel(leadName string) *Label {
return NewLabel(Lead, leadName)
}

// IDAllureLabel returns AllureID Label
func IDAllureLabel(allureID string) Label {
func IDAllureLabel(allureID string) *Label {
return NewLabel(AllureID, allureID)
}
10 changes: 5 additions & 5 deletions pkg/allure/link.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,24 +28,24 @@ const (
)

// NewLink Constructor. Builds and returns a new `allure.Link` object.
func NewLink(name string, _type LinkTypes, url string) Link {
return Link{name, string(_type), url}
func NewLink(name string, linkType LinkTypes, url string) *Link {
return &Link{name, string(linkType), url}
}

// TestCaseLink returns TESTCASE type link
func TestCaseLink(testCase string) Link {
func TestCaseLink(testCase string) *Link {
linkName := fmt.Sprintf("TestCase[%s]", testCase)
return NewLink(linkName, TESTCASE, fmt.Sprintf(getTestCasePattern(), testCase))
}

// IssueLink returns ISSUE type link
func IssueLink(issue string) Link {
func IssueLink(issue string) *Link {
linkName := fmt.Sprintf("Issue[%s]", issue)
return NewLink(linkName, ISSUE, fmt.Sprintf(getIssuePattern(), issue))
}

// LinkLink returns LINK type link
func LinkLink(linkname, link string) Link {
func LinkLink(linkname, link string) *Link {
return NewLink(linkname, LINK, link)
}

Expand Down
8 changes: 4 additions & 4 deletions pkg/allure/parameter.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ type Parameter struct {

// NewParameter Constructor. Builds and returns a new `Parameter` object,
// using `name` as the parameter name and `value`, as the value.
func NewParameter(name string, value ...interface{}) Parameter {
func NewParameter(name string, value ...interface{}) *Parameter {
val := trimBrackets(messageFromMsgAndArgs(value))
return Parameter{
return &Parameter{
Name: name,
Value: val,
}
Expand All @@ -27,11 +27,11 @@ func NewParameter(name string, value ...interface{}) Parameter {
// Each even string is considered a parameter name, and each odd-value of the parameter.
// If an odd number of lines is passed, the last line is discarded.
// Returns the list of parameters received after processing the passed list.
func NewParameters(kv ...interface{}) []Parameter {
func NewParameters(kv ...interface{}) []*Parameter {
if len(kv)%2 != 0 {
kv = kv[:len(kv)-1]
}
result := make([]Parameter, len(kv)/2)
result := make([]*Parameter, len(kv)/2)
for i := 0; i < len(kv); i += 2 {
val := trimBrackets(messageFromMsgAndArgs(kv[i+1]))
result[i/2] = NewParameter(messageFromMsgAndArgs(kv[i]), val)
Expand Down
62 changes: 43 additions & 19 deletions pkg/allure/result.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ type Result struct {
TestCaseID string `json:"testCaseId,omitempty"` // ID of the test case (based on the hash of the full call)
Description string `json:"description,omitempty"` // Test description
Attachments []*Attachment `json:"attachments,omitempty"` // Test case attachments
Parameters []Parameter `json:"parameters,omitempty"` // Test case parameters
Labels []Label `json:"labels,omitempty"` // Array of labels
Links []Link `json:"links,omitempty"` // Array of references
Parameters []*Parameter `json:"parameters,omitempty"` // Test case parameters
Labels []*Label `json:"labels,omitempty"` // Array of labels
Links []*Link `json:"links,omitempty"` // Array of references
Steps []*Step `json:"steps,omitempty"` // Array of steps
ToPrint bool `json:"-"` // If false - the report will not be saved to a file
}
Expand Down Expand Up @@ -85,14 +85,22 @@ func (result *Result) addLabel(labelType LabelType, labelValue string) {
result.Labels = append(result.Labels, label)
}

// SetLabel Adds all passed in arguments `allure.Label` to the report
func (result *Result) SetLabel(labels ...Label) {
// AddLabel Adds all passed in arguments `allure.Label` to the report
func (result *Result) AddLabel(labels ...*Label) {
result.Labels = append(result.Labels, labels...)
}

// GetLabel Returns all `allure.Label` whose `LabelType` matches the one specified in the argument.
func (result *Result) GetLabel(labelType LabelType) []Label {
labels := make([]Label, 0)
// GetFirstLabel returns first label in labels list and true if something have been found, return false if nothing was found
func (result *Result) GetFirstLabel(labelType LabelType) (label *Label, ok bool) {
if labels := result.GetLabels(labelType); len(labels) > 0 {
return labels[0], true
}
return
}

// GetLabels Returns all `allure.Label` whose `LabelType` matches the one specified in the argument.
func (result *Result) GetLabels(labelType LabelType) []*Label {
labels := make([]*Label, 0)
for _, label := range result.Labels {
if label.Name == labelType.ToString() {
labels = append(labels, label)
Expand All @@ -103,11 +111,11 @@ func (result *Result) GetLabel(labelType LabelType) []Label {

// SetNewLabelMap Adds all passed in arguments `allure.Label` to the report
func (result *Result) SetNewLabelMap(kv map[LabelType]string) {
var labels []Label
var labels []*Label
for k, v := range kv {
labels = append(labels, NewLabel(k, v))
}
result.SetLabel(labels...)
result.AddLabel(labels...)
}

// WithParentSuite Adds `allure.Label` with type `Parent` to the report.
Expand All @@ -116,21 +124,21 @@ func (result *Result) WithParentSuite(parentName string) *Result {
if parentName == "" {
return result
}
result.addLabel(ParentSuite, parentName)
result.ReplaceNewLabel(ParentSuite, parentName)
return result
}

// WithSuite Adds `allure.Label` with type `Suite` to the report.
// Returns a pointer to the current `allure.Result` (for Fluent Interface).
func (result *Result) WithSuite(suiteName string) *Result {
result.addLabel(Suite, suiteName)
result.ReplaceNewLabel(Suite, suiteName)
return result
}

// WithHost Adds `allure.Label` with type `Host` to the report.
// Returns a pointer to the current `allure.Result` (for Fluent Interface).
func (result *Result) WithHost(hostName string) *Result {
result.addLabel(Host, hostName)
result.ReplaceNewLabel(Host, hostName)
return result
}

Expand All @@ -146,35 +154,35 @@ func (result *Result) WithSubSuites(children ...string) *Result {
// WithFrameWork Adds `allure.Label` with type `Framework` to the report.
// Returns a pointer to the current `allure.Result` (for Fluent Interface).
func (result *Result) WithFrameWork(framework string) *Result {
result.addLabel(Framework, framework)
result.ReplaceNewLabel(Framework, framework)
return result
}

// WithLanguage Adds `allure.Label` with type `Language` to the report.
// Returns a pointer to the current `allure.Result` (for Fluent Interface).
func (result *Result) WithLanguage(language string) *Result {
result.addLabel(Language, language)
result.ReplaceNewLabel(Language, language)
return result
}

// WithThread Adds `allure.Label` with type `Thread` to the report.
// Returns a pointer to the current `allure.Result` (for Fluent Interface).
func (result *Result) WithThread(thread string) *Result {
result.addLabel(Thread, thread)
result.ReplaceNewLabel(Thread, thread)
return result
}

// WithPackage Adds `allure.Label` with type `Package` to the report.
// Returns a pointer to the current `allure.Result` (for Fluent Interface).
func (result *Result) WithPackage(pkg string) *Result {
result.addLabel(Package, pkg)
result.ReplaceNewLabel(Package, pkg)
return result
}

// WithLabels Adds an array of `allure.Label`.
// Returns a pointer to the current `allure.Result` (for Fluent Interface).
func (result *Result) WithLabels(label ...Label) *Result {
result.SetLabel(label...)
func (result *Result) WithLabels(label ...*Label) *Result {
result.AddLabel(label...)
return result
}

Expand Down Expand Up @@ -258,6 +266,22 @@ func (result *Result) Done() error {
return result.Print()
}

// ReplaceNewLabel creates new label and replaces it in the allure.Result object by label's name
func (result *Result) ReplaceNewLabel(name LabelType, value string) {
result.ReplaceLabel(NewLabel(name, value))
}

// ReplaceLabel replaces label in the allure.Result object by label's name
func (result *Result) ReplaceLabel(label *Label) {
for _, l := range result.Labels {
if label.Name == l.Name {
l.Value = label.Value
return
}
}
result.Labels = append(result.Labels, label)
}

// ToJSON marshall allure.Result to json file
func (result *Result) ToJSON() ([]byte, error) {
return json.Marshal(result)
Expand Down
Loading

0 comments on commit dea35d2

Please sign in to comment.