Skip to content

Commit

Permalink
Added links and layer (#50)
Browse files Browse the repository at this point in the history
Co-authored-by: Nikita Filonov <nikita.filonov@dif.tech>
  • Loading branch information
Nikita-Filonov and Nikita Filonov committed Oct 19, 2023
1 parent 01224ec commit fbff2e4
Show file tree
Hide file tree
Showing 9 changed files with 77 additions and 2 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,6 @@ vendor/
# Intellij IDEA folder
.idea/
/maven_reference_project/

# Mac OS
.DS_Store
14 changes: 14 additions & 0 deletions example/example_link_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package example

import (
"github.com/dailymotion/allure-go"
"testing"
)

func TestAllureWithLinks(t *testing.T) {
allure.Test(t, allure.Description("Test with links"),
allure.Link("https://github.com/", "GitHub Link"),
allure.Issue("https://github.com/", "GitHub Issue"),
allure.TestCase("https://github.com/", "GitHub TestCase"),
allure.Action(func() {}))
}
1 change: 1 addition & 0 deletions example/example_parameters_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ func TestAllureWithLabels(t *testing.T) {
allure.Story("story2"),
allure.Feature("feature1"),
allure.Feature("feature2"),
allure.Layer("integration-tests"),
allure.Tag("tag1"),
allure.Tags("tag2", "tag3"),
allure.Label("customLabel1", "customLabel1Value"),
Expand Down
1 change: 1 addition & 0 deletions interfaces.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package allure

type hasOptions interface {
addLink(url, name string, linkType LinkType)
addLabel(key string, value string)
addDescription(description string)
addParameter(name string, value interface{})
Expand Down
15 changes: 15 additions & 0 deletions link.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package allure

type LinkType string

const (
IssueType LinkType = "issue"
AnyLinkType LinkType = "link"
TestCaseType LinkType = "test_case"
)

type link struct {
Url string `json:"url,omitempty"`
Name string `json:"name,omitempty"`
Type LinkType `json:"type,omitempty"`
}
24 changes: 24 additions & 0 deletions options.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,30 @@ func Name(name string) Option {
}
}

func Layer(layer string) Option {
return func(r hasOptions) {
r.addLabel("layer", layer)
}
}

func Link(url, name string) Option {
return func(r hasOptions) {
r.addLink(url, name, AnyLinkType)
}
}

func Issue(url, name string) Option {
return func(r hasOptions) {
r.addLink(url, name, IssueType)
}
}

func TestCase(url, name string) Option {
return func(r hasOptions) {
r.addLink(url, name, TestCaseType)
}
}

func Suite(suite string) Option {
return func(r hasOptions) {
r.addLabel("suite", suite)
Expand Down
11 changes: 10 additions & 1 deletion result.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"github.com/pkg/errors"
)

//result is the top level report object for a test
// result is the top level report object for a test
type result struct {
UUID string `json:"uuid,omitempty"`
TestCaseID string `json:"testCaseId,omitempty"`
Expand All @@ -30,6 +30,7 @@ type result struct {
Children []string `json:"children,omitempty"`
FullName string `json:"fullName,omitempty"`
Labels []label `json:"labels,omitempty"`
Links []link `json:"links,omitempty"`
Test func() `json:"-"`
}

Expand Down Expand Up @@ -135,6 +136,14 @@ func (r *result) setDefaultLabels(t *testing.T) {
// Framework string
}

func (r *result) addLink(url, name string, linkType LinkType) {
r.Links = append(r.Links, link{
Url: url,
Name: name,
Type: linkType,
})
}

func (r *result) addLabel(name string, value string) {
r.Labels = append(r.Labels, label{
Name: name,
Expand Down
4 changes: 4 additions & 0 deletions step.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ func (s *stepObject) addReason(reason string) {
s.StatusDetails.Message = reason
}

func (s *stepObject) addLink(url, name string, linkType LinkType) {
// Step doesn't have links
}

func (s *stepObject) addLabel(key string, value string) {
// Step doesn't have labels
}
Expand Down
6 changes: 5 additions & 1 deletion test_phase_container.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ type container struct {
Stop int64 `json:"stop"`
}

//subContainer defines a step
// subContainer defines a step
type subContainer struct {
Name string `json:"name,omitempty"`
Status string `json:"status,omitempty"`
Expand All @@ -41,6 +41,10 @@ type subContainer struct {
Action func() `json:"-"`
}

func (s *subContainer) addLink(url, name string, linkType LinkType) {
panic("implement me")
}

func (sc *subContainer) addLabel(key string, value string) {
panic("implement me")
}
Expand Down

0 comments on commit fbff2e4

Please sign in to comment.