forked from SAP/jenkins-library
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkarmaExecuteTests.go
50 lines (43 loc) · 1.35 KB
/
karmaExecuteTests.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
package cmd
import (
"strings"
"github.com/SAP/jenkins-library/pkg/command"
"github.com/SAP/jenkins-library/pkg/log"
"github.com/SAP/jenkins-library/pkg/telemetry"
)
func karmaExecuteTests(config karmaExecuteTestsOptions, telemetryData *telemetry.CustomData) {
c := command.Command{}
// reroute command output to loging framework
// also log stdout as Karma reports into it
c.Stdout(log.Writer())
c.Stderr(log.Writer())
runKarma(config, &c)
}
func runKarma(config karmaExecuteTestsOptions, command command.ExecRunner) {
installCommandTokens := tokenize(config.InstallCommand)
runCommandTokens := tokenize(config.RunCommand)
modulePaths := config.Modules
for _, module := range modulePaths {
command.SetDir(module)
err := command.RunExecutable(installCommandTokens[0], installCommandTokens[1:]...)
if err != nil {
log.SetErrorCategory(log.ErrorCustom)
log.Entry().
WithError(err).
WithField("command", config.InstallCommand).
Fatal("failed to execute install command")
}
command.SetDir(module)
err = command.RunExecutable(runCommandTokens[0], runCommandTokens[1:]...)
if err != nil {
log.SetErrorCategory(log.ErrorTest)
log.Entry().
WithError(err).
WithField("command", config.RunCommand).
Fatal("failed to execute run command")
}
}
}
func tokenize(command string) []string {
return strings.Split(command, " ")
}