You've already forked sap-jenkins-library
mirror of
https://github.com/SAP/jenkins-library.git
synced 2025-09-16 09:26:22 +02:00
fix(golangBuild) pass testOptions to gotestsum (#4077)
Co-authored-by: Philipp Stehle <philipp.stehle@sap.com> Co-authored-by: Pavel Busko <pavel.busko@sap.com>
This commit is contained in:
@@ -361,7 +361,9 @@ func prepareGolangEnvironment(config *golangBuildOptions, goModFile *modfile.Fil
|
||||
|
||||
func runGolangTests(config *golangBuildOptions, utils golangBuildUtils) (bool, error) {
|
||||
// execute gotestsum in order to have more output options
|
||||
if err := utils.RunExecutable("gotestsum", "--junitfile", golangUnitTestOutput, "--", fmt.Sprintf("-coverprofile=%v", coverageFile), "./..."); err != nil {
|
||||
testOptions := []string{"--junitfile", golangUnitTestOutput, "--", fmt.Sprintf("-coverprofile=%v", coverageFile), "./..."}
|
||||
testOptions = append(testOptions, config.TestOptions...)
|
||||
if err := utils.RunExecutable("gotestsum", testOptions...); err != nil {
|
||||
exists, fileErr := utils.FileExists(golangUnitTestOutput)
|
||||
if !exists || fileErr != nil {
|
||||
log.SetErrorCategory(log.ErrorBuild)
|
||||
|
@@ -132,6 +132,27 @@ go 1.17`
|
||||
assert.Equal(t, []string{"build", "-trimpath", "-ldflags", "test", "package/foo"}, utils.ExecMockRunner.Calls[2].Params)
|
||||
})
|
||||
|
||||
t.Run("success - test flags", func(t *testing.T) {
|
||||
config := golangBuildOptions{
|
||||
RunTests: true,
|
||||
Packages: []string{"package/foo"},
|
||||
TargetArchitectures: []string{"linux,amd64"},
|
||||
TestOptions: []string{"--foo", "--bar"},
|
||||
}
|
||||
utils := newGolangBuildTestsUtils()
|
||||
utils.FilesMock.AddFile("go.mod", []byte(modTestFile))
|
||||
telemetryData := telemetry.CustomData{}
|
||||
|
||||
err := runGolangBuild(&config, &telemetryData, utils, &cpe)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, "go", utils.ExecMockRunner.Calls[0].Exec)
|
||||
assert.Equal(t, []string{"install", "gotest.tools/gotestsum@latest"}, utils.ExecMockRunner.Calls[0].Params)
|
||||
assert.Equal(t, "gotestsum", utils.ExecMockRunner.Calls[1].Exec)
|
||||
assert.Equal(t, []string{"--junitfile", "TEST-go.xml", "--", fmt.Sprintf("-coverprofile=%v", coverageFile), "./...", "--foo", "--bar"}, utils.ExecMockRunner.Calls[1].Params)
|
||||
assert.Equal(t, "go", utils.ExecMockRunner.Calls[2].Exec)
|
||||
assert.Equal(t, []string{"build", "-trimpath", "package/foo"}, utils.ExecMockRunner.Calls[2].Params)
|
||||
})
|
||||
|
||||
t.Run("success - tests with coverage", func(t *testing.T) {
|
||||
config := golangBuildOptions{
|
||||
RunTests: true,
|
||||
|
Reference in New Issue
Block a user