-
Notifications
You must be signed in to change notification settings - Fork 144
/
process_files.go
117 lines (101 loc) · 2.6 KB
/
process_files.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
package venom
import (
"fmt"
"io"
"io/ioutil"
"os"
"path/filepath"
"sort"
"strings"
log "github.com/Sirupsen/logrus"
"gopkg.in/cheggaaa/pb.v1"
"gopkg.in/yaml.v2"
)
func getFilesPath(path []string, exclude []string) []string {
var filesPath []string
var fpathsExcluded []string
if len(exclude) > 0 {
for _, p := range exclude {
pe, erre := filepath.Glob(p)
if erre != nil {
log.Fatalf("Error reading files on path:%s :%s", path, erre)
}
fpathsExcluded = append(fpathsExcluded, pe...)
}
}
for _, p := range path {
fileInfo, _ := os.Stat(p)
if fileInfo != nil && fileInfo.IsDir() {
p = filepath.Dir(p) + "/*.yml"
log.Debugf("path computed:%s", path)
}
fpaths, errg := filepath.Glob(p)
if errg != nil {
log.Fatalf("Error reading files on path:%s :%s", path, errg)
}
for _, fp := range fpaths {
toExclude := false
for _, te := range fpathsExcluded {
if te == fp {
toExclude = true
break
}
}
if !toExclude && (strings.HasSuffix(fp, ".yml") || strings.HasSuffix(fp, ".yaml")) {
filesPath = append(filesPath, fp)
}
}
}
log.Debugf("files to run: %v", filesPath)
sort.Strings(filesPath)
return filesPath
}
func readFiles(variables map[string]string, detailsLevel string, filesPath []string, chanToRun chan<- TestSuite, writer io.Writer) (map[string]*pb.ProgressBar, error) {
bars := make(map[string]*pb.ProgressBar)
for _, f := range filesPath {
dat, errr := ioutil.ReadFile(f)
if errr != nil {
return nil, fmt.Errorf("Error while reading file %s err:%s", f, errr)
}
ts := TestSuite{}
ts.Templater = newTemplater(variables)
ts.Package = f
// Apply templater unitl there is no more modifications
// it permits to include testcase from env
out := ts.Templater.apply(dat)
for i := 0; i < 10; i++ {
tmp := ts.Templater.apply(out)
if string(tmp) == string(out) {
break
}
out = tmp
}
if err := yaml.Unmarshal(out, &ts); err != nil {
return nil, fmt.Errorf("Error while unmarshal file %s err:%s data:%s variables:%s", f, err, out, variables)
}
ts.Name += " [" + f + "]"
nSteps := 0
for _, tc := range ts.TestCases {
nSteps += len(tc.TestSteps)
if tc.Skipped == 1 {
ts.Skipped++
}
}
ts.Total = len(ts.TestCases)
b := pb.New(nSteps).Prefix(rightPad("⚙ "+ts.Package, " ", 47))
b.ShowCounters = false
b.Output = writer
if detailsLevel == DetailsLow {
b.ShowBar = false
b.ShowFinalTime = false
b.ShowPercent = false
b.ShowSpeed = false
b.ShowTimeLeft = false
}
if detailsLevel != DetailsLow {
bars[ts.Package] = b
}
chanToRun <- ts
}
return bars, nil
}