-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprocess_testsuite.go
189 lines (166 loc) · 4.42 KB
/
process_testsuite.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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
package venom
import (
"context"
"fmt"
"os"
"runtime/pprof"
"time"
"github.com/fatih/color"
"github.com/gosimple/slug"
"github.com/ovh/cds/sdk/interpolate"
log "github.com/sirupsen/logrus"
)
func (v *Venom) runTestSuite(ctx context.Context, ts *TestSuite) {
if v.Verbose == 3 {
var filename, filenameCPU, filenameMem string
if v.OutputDir != "" {
filename = v.OutputDir + "/"
}
filenameCPU = filename + "pprof_cpu_profile_" + ts.Filename + ".prof"
filenameMem = filename + "pprof_mem_profile_" + ts.Filename + ".prof"
fCPU, errCPU := os.Create(filenameCPU)
fMem, errMem := os.Create(filenameMem)
if errCPU != nil || errMem != nil {
log.Errorf("error while create profile file CPU:%v MEM:%v", errCPU, errMem)
} else {
pprof.StartCPUProfile(fCPU)
p := pprof.Lookup("heap")
defer p.WriteTo(fMem, 1)
defer pprof.StopCPUProfile()
}
}
// Intialiaze the testsuite varibles and compute a first interpolation over them
ts.Vars.AddAll(v.variables.Clone())
vars, _ := DumpStringPreserveCase(ts.Vars)
for k, v := range vars {
computedV, err := interpolate.Do(fmt.Sprintf("%v", v), vars)
if err != nil {
log.Errorf("error while computing variable %s=%q: %v", k, v, err)
}
ts.Vars.Add(k, computedV)
}
exePath, err := os.Executable()
if err != nil {
log.Errorf("failed to get executable path: %v", err)
} else {
ts.Vars.Add("venom.executable", exePath)
}
ts.Vars.Add("venom.libdir", v.LibDir)
ts.Vars.Add("venom.testsuite", ts.Name)
ts.ComputedVars = H{}
ctx = context.WithValue(ctx, ContextKey("testsuite"), ts.Name)
Info(ctx, "Starting testsuite")
defer Info(ctx, "Ending testsuite")
totalSteps := 0
for _, tc := range ts.TestCases {
totalSteps += len(tc.testSteps)
}
v.runTestCases(ctx, ts)
}
func (v *Venom) runTestCases(ctx context.Context, ts *TestSuite) {
var red = color.New(color.FgRed).SprintFunc()
var green = color.New(color.FgGreen).SprintFunc()
var cyan = color.New(color.FgCyan).SprintFunc()
var gray = color.New(color.Attribute(90)).SprintFunc()
v.Println(" • %s (%s)", ts.Name, ts.Package)
for i := range ts.TestCases {
tc := &ts.TestCases[i]
tc.IsEvaluated = true
v.Print(" \t• %s", tc.Name)
tc.Classname = ts.Filename
var hasFailure bool
var hasSkipped = len(tc.Skipped) > 0
if !hasSkipped {
start := time.Now()
v.runTestCase(ctx, ts, tc)
tc.Time = time.Since(start).Seconds()
}
if len(tc.Failures) > 0 {
ts.Failures += len(tc.Failures)
hasFailure = true
}
if len(tc.Errors) > 0 {
ts.Errors += len(tc.Errors)
hasFailure = true
}
if len(tc.Skipped) > 0 {
ts.Skipped += len(tc.Skipped)
hasSkipped = true
}
if hasSkipped {
v.Println(" %s", gray("SKIPPED"))
continue
}
if hasFailure {
v.Println(" %s", red("FAILURE"))
} else {
v.Println(" %s", green("SUCCESS"))
}
for _, i := range tc.computedInfo {
v.Println("\t %s %s", cyan("[info]"), cyan(i))
}
for _, i := range tc.computedVerbose {
v.PrintlnTrace(i)
}
if hasFailure {
for _, f := range tc.Failures {
v.Println("%s", red(f.Value))
}
for _, f := range tc.Errors {
v.Println("%s", red(f.Value))
}
}
if v.StopOnFailure && (len(tc.Failures) > 0 || len(tc.Errors) > 0) {
// break TestSuite
return
}
ts.ComputedVars.AddAllWithPrefix(tc.Name, tc.computedVars)
}
}
//Parse the suite to find unreplaced and extracted variables
func (v *Venom) parseTestSuite(ts *TestSuite) ([]string, []string, error) {
return v.parseTestCases(ts)
}
//Parse the testscases to find unreplaced and extracted variables
func (v *Venom) parseTestCases(ts *TestSuite) ([]string, []string, error) {
var vars []string
var extractsVars []string
for i := range ts.TestCases {
tc := &ts.TestCases[i]
tc.originalName = tc.Name
tc.Name = slug.Make(tc.Name)
tc.Vars = ts.Vars.Clone()
tc.Vars.Add("venom.testcase", tc.Name)
if len(tc.Skipped) == 0 {
tvars, tExtractedVars, err := v.parseTestCase(ts, tc)
if err != nil {
return nil, nil, err
}
for _, k := range tvars {
var found bool
for i := 0; i < len(vars); i++ {
if vars[i] == k {
found = true
break
}
}
if !found {
vars = append(vars, k)
}
}
for _, k := range tExtractedVars {
var found bool
for i := 0; i < len(extractsVars); i++ {
if extractsVars[i] == k {
found = true
break
}
}
if !found {
extractsVars = append(extractsVars, k)
}
}
}
}
return vars, extractsVars, nil
}