1
0
mirror of https://github.com/SAP/jenkins-library.git synced 2024-12-14 11:03:09 +02:00
sap-jenkins-library/cmd/karmaExecuteTests.go
Oliver Nocon d053653a93
Add golang implementation for karma tests (#919)
* Provide golang based karma step
2019-10-25 14:58:59 +02:00

36 lines
1.1 KiB
Go

package cmd
import (
"strings"
"github.com/SAP/jenkins-library/pkg/command"
"github.com/pkg/errors"
)
func karmaExecuteTests(myKarmaExecuteTestsOptions karmaExecuteTestsOptions) error {
c := command.Command{}
return runKarma(myKarmaExecuteTestsOptions, &c)
}
func runKarma(myKarmaExecuteTestsOptions karmaExecuteTestsOptions, command execRunner) error {
installCommandTokens := tokenize(myKarmaExecuteTestsOptions.InstallCommand)
command.Dir(myKarmaExecuteTestsOptions.ModulePath)
err := command.RunExecutable(installCommandTokens[0], installCommandTokens[1:]...)
if err != nil {
return errors.Wrapf(err, "failed to execute install command '%v'", myKarmaExecuteTestsOptions.InstallCommand)
}
runCommandTokens := tokenize(myKarmaExecuteTestsOptions.RunCommand)
command.Dir(myKarmaExecuteTestsOptions.ModulePath)
err = command.RunExecutable(runCommandTokens[0], runCommandTokens[1:]...)
if err != nil {
return errors.Wrapf(err, "failed to execute run command '%v'", myKarmaExecuteTestsOptions.RunCommand)
}
return nil
}
func tokenize(command string) []string {
return strings.Split(command, " ")
}