diff --git a/.gitignore b/.gitignore index 18b32ae..a9b4cdf 100644 --- a/.gitignore +++ b/.gitignore @@ -19,3 +19,6 @@ vendor/ # Intellij IDEA folder .idea/ /maven_reference_project/ + +# Mac OS +.DS_Store diff --git a/example/example_link_test.go b/example/example_link_test.go new file mode 100644 index 0000000..1f5e93d --- /dev/null +++ b/example/example_link_test.go @@ -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() {})) +} diff --git a/example/example_parameters_test.go b/example/example_parameters_test.go index 6e7773a..788e45d 100644 --- a/example/example_parameters_test.go +++ b/example/example_parameters_test.go @@ -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"), diff --git a/interfaces.go b/interfaces.go index 18978b4..0b4e302 100644 --- a/interfaces.go +++ b/interfaces.go @@ -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{}) diff --git a/link.go b/link.go new file mode 100644 index 0000000..93f9ba4 --- /dev/null +++ b/link.go @@ -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"` +} diff --git a/options.go b/options.go index 87c704d..28f669c 100644 --- a/options.go +++ b/options.go @@ -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) diff --git a/result.go b/result.go index 1ced81f..de89579 100644 --- a/result.go +++ b/result.go @@ -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"` @@ -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:"-"` } @@ -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, diff --git a/step.go b/step.go index 818327a..78ceebd 100644 --- a/step.go +++ b/step.go @@ -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 } diff --git a/test_phase_container.go b/test_phase_container.go index bd390fb..023e438 100644 --- a/test_phase_container.go +++ b/test_phase_container.go @@ -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"` @@ -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") }