2019-10-25 14:58:59 +02:00
|
|
|
package cmd
|
|
|
|
|
|
|
|
import (
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
"github.com/SAP/jenkins-library/pkg/command"
|
2019-11-04 15:43:33 +02:00
|
|
|
"github.com/SAP/jenkins-library/pkg/log"
|
2020-02-04 11:46:43 +02:00
|
|
|
"github.com/SAP/jenkins-library/pkg/telemetry"
|
2019-10-25 14:58:59 +02:00
|
|
|
)
|
|
|
|
|
2020-02-04 11:46:43 +02:00
|
|
|
func karmaExecuteTests(config karmaExecuteTestsOptions, telemetryData *telemetry.CustomData) {
|
2019-10-25 14:58:59 +02:00
|
|
|
c := command.Command{}
|
2019-11-04 15:43:33 +02:00
|
|
|
// reroute command output to loging framework
|
|
|
|
// also log stdout as Karma reports into it
|
2020-05-06 13:35:40 +02:00
|
|
|
c.Stdout(log.Writer())
|
|
|
|
c.Stderr(log.Writer())
|
2020-02-04 11:46:43 +02:00
|
|
|
runKarma(config, &c)
|
2019-10-25 14:58:59 +02:00
|
|
|
}
|
|
|
|
|
2020-07-01 11:28:16 +02:00
|
|
|
func runKarma(config karmaExecuteTestsOptions, command command.ExecRunner) {
|
2020-02-04 11:46:43 +02:00
|
|
|
installCommandTokens := tokenize(config.InstallCommand)
|
|
|
|
runCommandTokens := tokenize(config.RunCommand)
|
2021-04-15 13:58:23 +02:00
|
|
|
modulePaths := config.Modules
|
|
|
|
|
|
|
|
for _, module := range modulePaths {
|
|
|
|
command.SetDir(module)
|
|
|
|
err := command.RunExecutable(installCommandTokens[0], installCommandTokens[1:]...)
|
|
|
|
if err != nil {
|
2021-05-10 17:44:28 +02:00
|
|
|
log.SetErrorCategory(log.ErrorCustom)
|
2021-04-15 13:58:23 +02:00
|
|
|
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 {
|
2021-05-10 17:44:28 +02:00
|
|
|
log.SetErrorCategory(log.ErrorTest)
|
2021-04-15 13:58:23 +02:00
|
|
|
log.Entry().
|
|
|
|
WithError(err).
|
|
|
|
WithField("command", config.RunCommand).
|
|
|
|
Fatal("failed to execute run command")
|
|
|
|
}
|
2019-10-25 14:58:59 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func tokenize(command string) []string {
|
|
|
|
return strings.Split(command, " ")
|
|
|
|
}
|