1
0
mirror of https://github.com/SAP/jenkins-library.git synced 2024-12-14 11:03:09 +02:00
sap-jenkins-library/cmd/uiVeri5ExecuteTests.go
lndrschlz e60bdb94a6
feat(uiVeri5): golang implmementation for uiVeri5ExecuteTests (#2394)
* added uiVeri5ExecuteTests step files

* added confPath an regenerated step

* added test for uiVeri5ExecuteTests

* config modified

* added groovy wrapper

* ambiguous method fixed

* uiveri5 wrapper

* removed install command

* fixed defaults

* added testOptions as confPath arg

* test set env

* test npm install local

* changed env settings

* tests regenerated

* go generate

* fix code climate

* overwrite groovy step

* remove groovy wrapper go

* unstash piper bin

* test older node version

* test piperExecuteBin

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* refactored params

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* set testServerUrl as os env for uiveri5

* Update config.yml

* fix naming of testServerUrl param

* wip

* refactored setEnv and fixed tests

* wip

* step param for NPM_CONFIG_PREFIX

* fix runCommand

* refactored step param, regenerate, docu, fix tests

* fix groovy wrapper test

* cleanup

* add to CommonStepsTest field whitelist

* fixed default pipeline environment vars

* fix []string default

* fix metadata.go bug

* added test for docu metadata gen

* fix metadata_test.go in doc gen

* Update metadata_generated.go

* Update metadata_generated.go

* remove npm config prefix param; doc fix

* remove tab

* changed npm config prefix

* removed groovy wrapper test

* removed groovy step defaults

* modify path variable

* modified npm config prefix

* fix error wrapper and tests

* doc update

* add testRepository support

* wip

* fix testRepository param

* wip

* add utils

* init stash content

* wip

* wip

* wip

* add comment for deprecated parameters

* fixed commonStepTest

* fixed commonStepTest

* added error category for testOptions failure

* Update vars/uiVeri5ExecuteTests.groovy

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

* Update vars/uiVeri5ExecuteTests.groovy

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

* fix condition

Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com>
2021-01-28 11:31:24 +01:00

50 lines
1.7 KiB
Go

package cmd
import (
"os"
"strings"
"github.com/SAP/jenkins-library/pkg/command"
"github.com/SAP/jenkins-library/pkg/log"
"github.com/SAP/jenkins-library/pkg/telemetry"
"github.com/pkg/errors"
)
func uiVeri5ExecuteTests(config uiVeri5ExecuteTestsOptions, telemetryData *telemetry.CustomData) {
// for command execution use Command
c := command.Command{}
// reroute command output to logging framework
c.Stdout(log.Writer())
c.Stderr(log.Writer())
// error situations should stop execution through log.Entry().Fatal() call which leads to an os.Exit(1) in the end
err := runUIVeri5(&config, &c)
if err != nil {
log.Entry().WithError(err).Fatal("step execution failed")
}
}
func runUIVeri5(config *uiVeri5ExecuteTestsOptions, command command.ExecRunner) error {
envs := []string{"NPM_CONFIG_PREFIX=~/.npm-global"}
path := "PATH=" + os.Getenv("PATH") + ":~/.npm-global/bin"
envs = append(envs, path)
if config.TestServerURL != "" {
envs = append(envs, "TARGET_SERVER_URL="+config.TestServerURL)
}
command.SetEnv(envs)
installCommandTokens := strings.Split(config.InstallCommand, " ")
if err := command.RunExecutable(installCommandTokens[0], installCommandTokens[1:]...); err != nil {
return errors.Wrapf(err, "failed to execute install command: %v", config.InstallCommand)
}
if config.TestOptions != "" {
log.SetErrorCategory(log.ErrorConfiguration)
return errors.Errorf("parameter testOptions no longer supported, please use runOptions parameter instead.")
}
if err := command.RunExecutable(config.RunCommand, config.RunOptions...); err != nil {
return errors.Wrapf(err, "failed to execute run command: %v %v", config.RunCommand, config.RunOptions)
}
return nil
}