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
Mikalai Dzemidzenka 61f4c5245a
feat(karma): migrate karmaExecuteTests to go implementation (#2695)
* convert karmaExecuteTests to go implementation

* removed KarmaExecuteTestsTest.groovy

* added KarmaExecuteTests to fieldRelatedWhiteList

* Update vars/karmaExecuteTests.groovy

Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com>

* Update resources/metadata/karmaExecuteTests.yaml

Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com>

* Update resources/metadata/karmaExecuteTests.yaml

Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com>

* added reference seleniumHubCredentialsId to yaml file, fixed modules code

* karmaExecuteTests.yaml renamed to karma.yaml

Co-authored-by: lndrschlz <leander.schulz01@sap.com>
Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com>
2021-04-15 13:58:23 +02:00

49 lines
1.3 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)
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.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.Entry().
WithError(err).
WithField("command", config.RunCommand).
Fatal("failed to execute run command")
}
}
}
func tokenize(command string) []string {
return strings.Split(command, " ")
}