-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy patherror.go
118 lines (97 loc) · 2.52 KB
/
error.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
package errors
const (
actualField = "Actual"
expectedField = "Expected"
)
// CuteError ...
type CuteError interface {
error
WithNameError
WithFields
WithAttachments
}
// WithNameError is interface for creates allure step.
// If function returns error, which implement this interface, allure step will create automatically
type WithNameError interface {
GetName() string
SetName(string)
}
// WithFields is interface for put parameters in allure step.
// If function returns error, which implement this interface, parameters will add to allure step
type WithFields interface {
GetFields() map[string]interface{}
PutFields(map[string]interface{})
}
// Attachment represents an attachment to Allure with properties like name, MIME type, and content.
type Attachment struct {
Name string // Name of the attachment.
MimeType string // MIME type of the attachment.
Content []byte // Content of the attachment.
}
// WithAttachments is an interface that defines methods for managing attachments.
type WithAttachments interface {
GetAttachments() []*Attachment
PutAttachment(a *Attachment)
}
type assertError struct {
optional bool
require bool
name string
message string
fields map[string]interface{}
attachments []*Attachment
}
// NewAssertError ...
func NewAssertError(name string, message string, actual interface{}, expected interface{}) error {
return &assertError{
name: name,
message: message,
fields: map[string]interface{}{
actualField: actual,
expectedField: expected,
},
}
}
// NewEmptyAssertError ...
func NewEmptyAssertError(name string, message string) CuteError {
return &assertError{
name: name,
message: message,
fields: map[string]interface{}{},
}
}
func (a *assertError) Error() string {
return a.message
}
func (a *assertError) GetName() string {
return a.name
}
func (a *assertError) SetName(name string) {
a.name = name
}
func (a *assertError) GetFields() map[string]interface{} {
return a.fields
}
func (a *assertError) PutFields(fields map[string]interface{}) {
for k, v := range fields {
a.fields[k] = v
}
}
func (a *assertError) GetAttachments() []*Attachment {
return a.attachments
}
func (a *assertError) PutAttachment(attachment *Attachment) {
a.attachments = append(a.attachments, attachment)
}
func (a *assertError) IsOptional() bool {
return a.optional
}
func (a *assertError) SetOptional(opt bool) {
a.optional = opt
}
func (a *assertError) IsRequire() bool {
return a.require
}
func (a *assertError) SetRequire(b bool) {
a.require = b
}