-
Notifications
You must be signed in to change notification settings - Fork 144
/
process.go
89 lines (73 loc) · 1.99 KB
/
process.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
package venom
import (
"errors"
"io"
"strings"
"sync"
log "github.com/Sirupsen/logrus"
)
// Process runs tests suite and return a Tests result
func Process(path []string, variables map[string]string, exclude []string, parallel int, logLevel string, detailsLevel string, writer io.Writer) (*Tests, error) {
switch logLevel {
case "debug":
log.SetLevel(log.DebugLevel)
case "info":
log.SetLevel(log.InfoLevel)
case "error":
log.SetLevel(log.WarnLevel)
default:
log.SetLevel(log.WarnLevel)
}
log.SetOutput(writer)
switch detailsLevel {
case DetailsLow, DetailsMedium, DetailsHigh:
log.Infof("Detail Level: %s", detailsLevel)
default:
return nil, errors.New("Invalid details. Must be low, medium or high")
}
chanEnd := make(chan TestSuite, 1)
parallels := make(chan TestSuite, parallel)
wg := sync.WaitGroup{}
testsResult := &Tests{}
filesPath := getFilesPath(path, exclude)
wg.Add(len(filesPath))
chanToRun := make(chan TestSuite, len(filesPath)+1)
go computeStats(testsResult, chanEnd, &wg)
bars, err := readFiles(variables, detailsLevel, filesPath, chanToRun, writer)
if err != nil {
return nil, err
}
pool := initBars(detailsLevel, bars)
go func() {
for ts := range chanToRun {
parallels <- ts
go func(ts TestSuite) {
runTestSuite(&ts, bars, detailsLevel)
chanEnd <- ts
<-parallels
}(ts)
}
}()
wg.Wait()
endBars(detailsLevel, pool)
return testsResult, nil
}
func computeStats(testsResult *Tests, chanEnd <-chan TestSuite, wg *sync.WaitGroup) {
for t := range chanEnd {
testsResult.TestSuites = append(testsResult.TestSuites, t)
if t.Failures > 0 {
testsResult.TotalKO += t.Failures
} else {
testsResult.TotalOK += len(t.TestCases) - t.Failures
}
if t.Skipped > 0 {
testsResult.TotalSkipped += t.Skipped
}
testsResult.Total = testsResult.TotalKO + testsResult.TotalOK + testsResult.TotalSkipped
wg.Done()
}
}
func rightPad(s string, padStr string, pLen int) string {
o := s + strings.Repeat(padStr, pLen)
return o[0:pLen]
}