1
0
mirror of https://github.com/SAP/jenkins-library.git synced 2024-12-12 10:55:20 +02:00
sap-jenkins-library/cmd/karmaExecuteTests.go
Marcus Holl 4f2ba73314
[refactoring] move the shell/command related interfaces into pkg/command (#1737)
* [refactoring] move the shell/command related interfaces into pkg/command

otherwise we are not able to use the corresponding mocks for the items contained in pkg since
these interfaces are not visible from the pkg folder

Co-authored-by: Daniel Kurzynski <daniel.kurzynski@sap.com>
2020-07-01 11:28:16 +02:00

45 lines
1.2 KiB
Go

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)
command.SetDir(config.ModulePath)
err := command.RunExecutable(installCommandTokens[0], installCommandTokens[1:]...)
if err != nil {
log.Entry().
WithError(err).
WithField("command", config.InstallCommand).
Fatal("failed to execute install command")
}
runCommandTokens := tokenize(config.RunCommand)
command.SetDir(config.ModulePath)
err = command.RunExecutable(runCommandTokens[0], runCommandTokens[1:]...)
if err != nil {
log.Entry().
WithError(err).
WithField("command", config.RunCommand).
Fatal("failed to execute run command")
}
}
func tokenize(command string) []string {
return strings.Split(command, " ")
}