forked from ozontech/allure-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathattachments_test.go
157 lines (128 loc) · 5.56 KB
/
attachments_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
//go:build examples_new
// +build examples_new
package suite_demo
import (
"encoding/json"
"testing"
"github.com/ozontech/allure-go/pkg/allure"
"github.com/ozontech/allure-go/pkg/framework/provider"
"github.com/ozontech/allure-go/pkg/framework/suite"
)
type JSONStruct struct {
Message string `json:"message"`
}
type AttachmentTestDemoSuite struct {
suite.Suite
}
func (s *AttachmentTestDemoSuite) TestAttachment(t provider.T) {
t.Epic("Demo")
t.Feature("Attachments")
t.Title("Test Attachments")
t.Description(`
Test's test body and all steps inside can contain attachments`)
t.Tags("Attachments", "BeforeAfter", "Steps")
attachmentText := `THIS IS A TEXT ATTACHMENT`
t.WithAttachments(allure.NewAttachment("Text Attachment if TestAttachment", allure.Text, []byte(attachmentText)))
step := allure.NewSimpleStep("Step A")
var ExampleJson = JSONStruct{"this is JSON message"}
attachmentJSON, _ := json.Marshal(ExampleJson)
step.WithAttachments(allure.NewAttachment("Json Attachment for Step A", allure.JSON, attachmentJSON))
t.Step(step)
}
type AttachmentDemoSuite struct {
suite.Suite
}
func (s *AttachmentDemoSuite) BeforeAll(t provider.T) {
// this action will create a step in Set up
attachmentText := `THIS IS A TEXT ATTACHMENT`
t.WithAttachments(allure.NewAttachment("Text Attachment for Before suite", allure.Text, []byte(attachmentText)))
step := allure.NewSimpleStep("Before suite Step")
var ExampleJson = JSONStruct{"This is BeforeAll JSON message"}
attachmentJSON, _ := json.Marshal(ExampleJson)
step.WithAttachments(allure.NewAttachment("Json Attachment for Before suite Step", allure.JSON, attachmentJSON))
t.Step(step)
}
func (s *AttachmentDemoSuite) BeforeEach(t provider.T) {
// this action will create a step in Set up
attachmentText := `THIS IS A TEXT ATTACHMENT`
t.WithAttachments(allure.NewAttachment("Text Attachment for Before Test", allure.Text, []byte(attachmentText)))
step := allure.NewSimpleStep("Before Test Step")
var ExampleJson = JSONStruct{"This is BeforeEach JSON message"}
attachmentJSON, _ := json.Marshal(ExampleJson)
step.WithAttachments(allure.NewAttachment("Json Attachment for Before Test Step", allure.JSON, attachmentJSON))
t.Step(step)
}
func (s *AttachmentDemoSuite) AfterAll(t provider.T) {
// this action will create a step in Tear down
attachmentText := `THIS IS A TEXT ATTACHMENT`
t.WithAttachments(allure.NewAttachment("Text Attachment for After suite", allure.Text, []byte(attachmentText)))
step := allure.NewSimpleStep("After suite Step")
var ExampleJson = JSONStruct{"This is AfterAll JSON message"}
attachmentJSON, _ := json.Marshal(ExampleJson)
step.WithAttachments(allure.NewAttachment("Json Attachment for After suite Step", allure.JSON, attachmentJSON))
t.Step(step)
}
func (s *AttachmentDemoSuite) AfterEach(t provider.T) {
// this action will create a step in Tear down
attachmentText := `THIS IS A TEXT ATTACHMENT`
t.WithAttachments(allure.NewAttachment("Text Attachment for After Test", allure.Text, []byte(attachmentText)))
step := allure.NewSimpleStep("After Test Step")
var ExampleJson = JSONStruct{"This is AfterEach JSON message"}
attachmentJSON, _ := json.Marshal(ExampleJson)
step.WithAttachments(allure.NewAttachment("Json Attachment for After Test Step", allure.JSON, attachmentJSON))
t.Step(step)
}
func (s *AttachmentDemoSuite) TestAttachment_1(t provider.T) {
t.Epic("Demo")
t.Feature("Attachments")
t.Title("Test with Before/After Attachments")
t.Description(`
Test "Set up", Test "Tear down", suite "Set up", suite "Tear down"
and all steps inside can contain attachments`)
t.Tags("Attachments", "BeforeAfter", "Steps")
}
type NestedAttachmentDemoSuite struct {
suite.Suite
}
func (s *NestedAttachmentDemoSuite) BeforeAll(t provider.T) {
t.WithNewStep("SetupSuite step", func(ctx provider.StepCtx) {
attachmentText := `THIS IS A TEXT ATTACHMENT`
ctx.WithAttachments(allure.NewAttachment("Text Attachment for Before all", allure.Text, []byte(attachmentText)))
})
}
func (s *NestedAttachmentDemoSuite) AfterAll(t provider.T) {
t.WithNewStep("TearDownSuite step", func(ctx provider.StepCtx) {
attachmentText := `THIS IS A TEXT ATTACHMENT`
ctx.WithAttachments(allure.NewAttachment("Text Attachment for After all", allure.Text, []byte(attachmentText)))
})
}
func (s *NestedAttachmentDemoSuite) BeforeEach(t provider.T) {
t.WithNewStep("SetupTest step", func(ctx provider.StepCtx) {
attachmentText := `THIS IS A TEXT ATTACHMENT`
ctx.WithAttachments(allure.NewAttachment("Text Attachment for Before Test", allure.Text, []byte(attachmentText)))
})
}
func (s *NestedAttachmentDemoSuite) AfterEach(t provider.T) {
t.WithNewStep("TearDownTest step", func(ctx provider.StepCtx) {
attachmentText := `THIS IS A TEXT ATTACHMENT`
ctx.WithAttachments(allure.NewAttachment("Text Attachment for After Test", allure.Text, []byte(attachmentText)))
})
}
func (s *NestedAttachmentDemoSuite) TestNestedAttachment(t provider.T) {
t.Epic("Demo")
t.Feature("Attachments")
t.Title("Test NestedAttachments")
t.Description(`
Test "Set up", Test "Tear down", suite "Set up", suite "Tear down" test body has step with attachmentt.`)
t.Tags("Attachments", "Nesting", "Steps", "BeforeAfter")
t.WithNewStep("TestNestedAttachment step", func(ctx provider.StepCtx) {
attachmentText := `THIS IS A TEXT ATTACHMENT`
ctx.WithAttachments(allure.NewAttachment("Text Attachment for After Test", allure.Text, []byte(attachmentText)))
})
}
func TestAttachments(t *testing.T) {
t.Parallel()
suite.RunSuite(t, new(AttachmentTestDemoSuite))
suite.RunSuite(t, new(AttachmentDemoSuite))
suite.RunSuite(t, new(NestedAttachmentDemoSuite))
}