Skip to content

Commit fbff2e4

Browse files
Nikita-FilonovNikita Filonov
andauthored
Added links and layer (#50)
Co-authored-by: Nikita Filonov <nikita.filonov@dif.tech>
1 parent 01224ec commit fbff2e4

File tree

9 files changed

+77
-2
lines changed

9 files changed

+77
-2
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,6 @@ vendor/
1919
# Intellij IDEA folder
2020
.idea/
2121
/maven_reference_project/
22+
23+
# Mac OS
24+
.DS_Store

example/example_link_test.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package example
2+
3+
import (
4+
"github.com/dailymotion/allure-go"
5+
"testing"
6+
)
7+
8+
func TestAllureWithLinks(t *testing.T) {
9+
allure.Test(t, allure.Description("Test with links"),
10+
allure.Link("https://github.com/", "GitHub Link"),
11+
allure.Issue("https://github.com/", "GitHub Issue"),
12+
allure.TestCase("https://github.com/", "GitHub TestCase"),
13+
allure.Action(func() {}))
14+
}

example/example_parameters_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ func TestAllureWithLabels(t *testing.T) {
9292
allure.Story("story2"),
9393
allure.Feature("feature1"),
9494
allure.Feature("feature2"),
95+
allure.Layer("integration-tests"),
9596
allure.Tag("tag1"),
9697
allure.Tags("tag2", "tag3"),
9798
allure.Label("customLabel1", "customLabel1Value"),

interfaces.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package allure
22

33
type hasOptions interface {
4+
addLink(url, name string, linkType LinkType)
45
addLabel(key string, value string)
56
addDescription(description string)
67
addParameter(name string, value interface{})

link.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package allure
2+
3+
type LinkType string
4+
5+
const (
6+
IssueType LinkType = "issue"
7+
AnyLinkType LinkType = "link"
8+
TestCaseType LinkType = "test_case"
9+
)
10+
11+
type link struct {
12+
Url string `json:"url,omitempty"`
13+
Name string `json:"name,omitempty"`
14+
Type LinkType `json:"type,omitempty"`
15+
}

options.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,30 @@ func Name(name string) Option {
9898
}
9999
}
100100

101+
func Layer(layer string) Option {
102+
return func(r hasOptions) {
103+
r.addLabel("layer", layer)
104+
}
105+
}
106+
107+
func Link(url, name string) Option {
108+
return func(r hasOptions) {
109+
r.addLink(url, name, AnyLinkType)
110+
}
111+
}
112+
113+
func Issue(url, name string) Option {
114+
return func(r hasOptions) {
115+
r.addLink(url, name, IssueType)
116+
}
117+
}
118+
119+
func TestCase(url, name string) Option {
120+
return func(r hasOptions) {
121+
r.addLink(url, name, TestCaseType)
122+
}
123+
}
124+
101125
func Suite(suite string) Option {
102126
return func(r hasOptions) {
103127
r.addLabel("suite", suite)

result.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212
"github.com/pkg/errors"
1313
)
1414

15-
//result is the top level report object for a test
15+
// result is the top level report object for a test
1616
type result struct {
1717
UUID string `json:"uuid,omitempty"`
1818
TestCaseID string `json:"testCaseId,omitempty"`
@@ -30,6 +30,7 @@ type result struct {
3030
Children []string `json:"children,omitempty"`
3131
FullName string `json:"fullName,omitempty"`
3232
Labels []label `json:"labels,omitempty"`
33+
Links []link `json:"links,omitempty"`
3334
Test func() `json:"-"`
3435
}
3536

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

139+
func (r *result) addLink(url, name string, linkType LinkType) {
140+
r.Links = append(r.Links, link{
141+
Url: url,
142+
Name: name,
143+
Type: linkType,
144+
})
145+
}
146+
138147
func (r *result) addLabel(name string, value string) {
139148
r.Labels = append(r.Labels, label{
140149
Name: name,

step.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ func (s *stepObject) addReason(reason string) {
3030
s.StatusDetails.Message = reason
3131
}
3232

33+
func (s *stepObject) addLink(url, name string, linkType LinkType) {
34+
// Step doesn't have links
35+
}
36+
3337
func (s *stepObject) addLabel(key string, value string) {
3438
// Step doesn't have labels
3539
}

test_phase_container.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ type container struct {
2626
Stop int64 `json:"stop"`
2727
}
2828

29-
//subContainer defines a step
29+
// subContainer defines a step
3030
type subContainer struct {
3131
Name string `json:"name,omitempty"`
3232
Status string `json:"status,omitempty"`
@@ -41,6 +41,10 @@ type subContainer struct {
4141
Action func() `json:"-"`
4242
}
4343

44+
func (s *subContainer) addLink(url, name string, linkType LinkType) {
45+
panic("implement me")
46+
}
47+
4448
func (sc *subContainer) addLabel(key string, value string) {
4549
panic("implement me")
4650
}

0 commit comments

Comments
 (0)