/
types.go
163 lines (140 loc) 路 6.3 KB
/
types.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
158
159
160
161
162
163
package venom
import "encoding/xml"
const (
// DetailsLow prints only summary results
DetailsLow = "low"
// DetailsMedium prints progress bar and summary
DetailsMedium = "medium"
// DetailsHigh prints progress bar and details
DetailsHigh = "high"
)
// Aliases contains list of aliases
type Aliases map[string]string
// ExecutorResult represents an executor result on a test step
type ExecutorResult map[string]interface{}
// StepAssertions contains step assertions
type StepAssertions struct {
Assertions []string `json:"assertions,omitempty" yaml:"assertions,omitempty"`
}
// StepExtracts contains "step extracts"
type StepExtracts struct {
Extracts map[string]string `json:"extracts,omitempty" yaml:"extracts,omitempty"`
}
// Executor execute a testStep.
type Executor interface {
// Run run a Test Step
Run(TestCaseContext, Logger, TestStep, string) (ExecutorResult, error)
}
// TestCaseContext represents the context of a testcase
type TestCaseContext interface {
Init() error
Close() error
SetTestCase(tc TestCase)
GetName() string
}
// CommonTestCaseContext represents a Default TestCase Context
type CommonTestCaseContext struct {
TestCaseContext
TestCase TestCase
Name string
}
// SetTestCase set testcase in context
func (tcc *CommonTestCaseContext) SetTestCase(tc TestCase) {
tcc.TestCase = tc
}
// GetName Get the context name
func (tcc *CommonTestCaseContext) GetName() string {
return tcc.Name
}
// ExecutorWrap contains an executor implementation and some attributes
type ExecutorWrap struct {
executor Executor
retry int // nb retry a test case if it is in failure.
delay int // delay between two retries
timeout int // timeout on executor
}
// executorWithDefaultAssertions execute a testStep.
type executorWithDefaultAssertions interface {
// GetDefaultAssertion returns default assertions
GetDefaultAssertions() *StepAssertions
}
type executorWithZeroValueResult interface {
ZeroValueResult() ExecutorResult
}
// Tests contains all informations about tests in a pipeline build
type Tests struct {
XMLName xml.Name `xml:"testsuites" json:"-" yaml:"-"`
Total int `xml:"-" json:"total"`
TotalOK int `xml:"-" json:"ok"`
TotalKO int `xml:"-" json:"ko"`
TotalSkipped int `xml:"-" json:"skipped"`
TestSuites []TestSuite `xml:"testsuite" json:"test_suites"`
}
// TestSuite is a single JUnit test suite which may contain many
// testcases.
type TestSuite struct {
XMLName xml.Name `xml:"testsuite" json:"-" yaml:"-"`
Disabled int `xml:"disabled,attr,omitempty" json:"disabled" yaml:"-"`
Errors int `xml:"errors,attr,omitempty" json:"errors" yaml:"-"`
Failures int `xml:"failures,attr,omitempty" json:"failures" yaml:"-"`
Hostname string `xml:"hostname,attr,omitempty" json:"hostname" yaml:"-"`
ID string `xml:"id,attr,omitempty" json:"id" yaml:"-"`
Name string `xml:"name,attr" json:"name" yaml:"name"`
Package string `xml:"package,attr,omitempty" json:"package" yaml:"-"`
Properties []Property `xml:"-" json:"properties" yaml:"-"`
Skipped int `xml:"skipped,attr,omitempty" json:"skipped" yaml:"skipped,omitempty"`
Total int `xml:"tests,attr" json:"total" yaml:"total,omitempty"`
TestCases []TestCase `xml:"testcase" hcl:"testcase" json:"tests" yaml:"testcases"`
Version string `xml:"version,omitempty" hcl:"version" json:"version" yaml:"version,omitempty"`
Time string `xml:"time,attr,omitempty" json:"time" yaml:"-"`
Timestamp string `xml:"timestamp,attr,omitempty" json:"timestamp" yaml:"-"`
Vars map[string]interface{} `xml:"-" json:"-" yaml:"vars"`
Templater *Templater `xml:"-" json:"-" yaml:"-"`
WorkDir string `xml:"-" json:"-" yaml:"-"`
}
// Property represents a key/value pair used to define properties.
type Property struct {
XMLName xml.Name `xml:"property" json:"-" yaml:"-"`
Name string `xml:"name,attr" json:"name" yaml:"-"`
Value string `xml:"value,attr" json:"value" yaml:"-"`
}
// TestCase is a single test case with its result.
type TestCase struct {
XMLName xml.Name `xml:"testcase" json:"-" yaml:"-"`
Classname string `xml:"classname,attr,omitempty" json:"classname" yaml:"-"`
Errors []Failure `xml:"error,omitempty" json:"errors" yaml:"errors,omitempty"`
Failures []Failure `xml:"failure,omitempty" json:"failures" yaml:"failures,omitempty"`
Name string `xml:"name,attr" json:"name" yaml:"name"`
Skipped []Skipped `xml:"skipped,omitempty" json:"skipped" yaml:"skipped,omitempty"`
Status string `xml:"status,attr,omitempty" json:"status" yaml:"status,omitempty"`
Systemout InnerResult `xml:"system-out,omitempty" json:"systemout" yaml:"systemout,omitempty"`
Systemerr InnerResult `xml:"system-err,omitempty" json:"systemerr" yaml:"systemerr,omitempty"`
Time string `xml:"time,attr,omitempty" json:"time" yaml:"time,omitempty"`
TestSteps []TestStep `xml:"-" hcl:"step" json:"steps" yaml:"steps"`
Context map[string]interface{} `xml:"-" json:"-" yaml:"context,omitempty"`
}
// TestStep represents a testStep
type TestStep map[string]interface{}
// Skipped contains data related to a skipped test.
type Skipped struct {
Value string `xml:",cdata" json:"value" yaml:"value,omitempty"`
}
// Failure contains data related to a failed test.
type Failure struct {
Value string `xml:",cdata" json:"value" yaml:"value,omitempty"`
Type string `xml:"type,attr,omitempty" json:"type" yaml:"type,omitempty"`
Message string `xml:"message,attr,omitempty" json:"message" yaml:"message,omitempty"`
}
// InnerResult is used by TestCase
type InnerResult struct {
Value string `xml:",cdata" json:"value" yaml:"value"`
}
//Logger is basically an interface for logrus.Entry
type Logger interface {
Debugf(format string, args ...interface{})
Infof(format string, args ...interface{})
Warnf(format string, args ...interface{})
Warningf(format string, args ...interface{})
Errorf(format string, args ...interface{})
Fatalf(format string, args ...interface{})
}