1
0
mirror of https://github.com/SAP/jenkins-library.git synced 2024-12-12 10:55:20 +02:00
sap-jenkins-library/cmd/uiVeri5ExecuteTests_test.go

56 lines
2.0 KiB
Go
Raw Normal View History

//go:build unit
// +build unit
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 12:31:24 +02:00
package cmd
import (
"testing"
"github.com/SAP/jenkins-library/pkg/mock"
"github.com/pkg/errors"
"github.com/stretchr/testify/assert"
)
func TestRunUIVeri5(t *testing.T) {
t.Run("success case", func(t *testing.T) {
opts := &uiVeri5ExecuteTestsOptions{
InstallCommand: "npm install ui5/uiveri5",
RunCommand: "uiveri5",
RunOptions: []string{"conf.js"},
TestServerURL: "http://path/to/deployment",
}
e := mock.ExecMockRunner{}
runUIVeri5(opts, &e)
assert.Equal(t, e.Env[0], "NPM_CONFIG_PREFIX=~/.npm-global", "NPM_CONFIG_PREFIX not set as expected")
assert.Contains(t, e.Env[1], "PATH", "PATH not in env list")
assert.Equal(t, e.Env[2], "TARGET_SERVER_URL=http://path/to/deployment", "TARGET_SERVER_URL not set as expected")
assert.Equal(t, e.Calls[0], mock.ExecCall{Exec: "npm", Params: []string{"install", "ui5/uiveri5"}}, "install command/params incorrect")
assert.Equal(t, e.Calls[1], mock.ExecCall{Exec: "uiveri5", Params: []string{"conf.js"}}, "run command/params incorrect")
})
t.Run("error case install command", func(t *testing.T) {
wantError := "failed to execute install command: fail install test: error case"
opts := &uiVeri5ExecuteTestsOptions{InstallCommand: "fail install test", RunCommand: "uiveri5"}
e := mock.ExecMockRunner{ShouldFailOnCommand: map[string]error{"fail install test": errors.New("error case")}}
err := runUIVeri5(opts, &e)
assert.EqualErrorf(t, err, wantError, "expected comman to exit with error")
})
t.Run("error case run command", func(t *testing.T) {
wantError := "failed to execute run command: fail uiveri5 testParam: error case"
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 12:31:24 +02:00
opts := &uiVeri5ExecuteTestsOptions{InstallCommand: "npm install ui5/uiveri5", RunCommand: "fail uiveri5", RunOptions: []string{"testParam"}}
e := mock.ExecMockRunner{ShouldFailOnCommand: map[string]error{"fail uiveri5": errors.New("error case")}}
err := runUIVeri5(opts, &e)
assert.EqualErrorf(t, err, wantError, "expected comman to exit with error")
})
}