/
scenarioDir.go
52 lines (47 loc) · 1.29 KB
/
scenarioDir.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
package mandoscontroller
import (
"errors"
"fmt"
"os"
"path"
"path/filepath"
"strings"
)
// RunAllJSONScenariosInDirectory walks directory, parses and prepares all json scenarios,
// then calls scenarioExecutor for each of them.
func (r *ScenarioRunner) RunAllJSONScenariosInDirectory(
generalTestPath string,
specificTestPath string,
allowedSuffix string,
excludedFilePatterns []string) error {
mainDirPath := path.Join(generalTestPath, specificTestPath)
var nrPassed, nrFailed, nrSkipped int
err := filepath.Walk(mainDirPath, func(testFilePath string, info os.FileInfo, err error) error {
if strings.HasSuffix(testFilePath, allowedSuffix) {
fmt.Printf("Scenario: %s ... ", shortenTestPath(testFilePath, generalTestPath))
if isExcluded(excludedFilePatterns, testFilePath, generalTestPath) {
nrSkipped++
fmt.Print(" skip\n")
} else {
r.Executor.Reset()
testErr := r.RunSingleJSONScenario(testFilePath)
if testErr == nil {
nrPassed++
fmt.Print(" ok\n")
} else {
nrFailed++
fmt.Printf(" FAIL: %s\n", testErr.Error())
}
}
}
return nil
})
if err != nil {
return err
}
fmt.Printf("Done. Passed: %d. Failed: %d. Skipped: %d.\n", nrPassed, nrFailed, nrSkipped)
if nrFailed > 0 {
return errors.New("Some tests failed")
}
return nil
}