Skip to content

Commit bd8b08b

Browse files
authored
fix: add missing return value for error (#5146)
1 parent bc8225c commit bd8b08b

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

pkg/transportrequest/cts/upload.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ func getFioriDeployStatement(
194194
if len(app.Name) > 0 {
195195
re := regexp.MustCompile(pattern)
196196
if !re.MatchString(app.Name) {
197-
fmt.Errorf("application name '%s' contains spaces or special characters. It is not according to the '%s'", app.Name, pattern)
197+
return "", fmt.Errorf("application name '%s' contains spaces or special characters and is not according to the regex '%s'.", app.Name, pattern)
198198
}
199199
log.Entry().Debugf("application name '%s' used from piper config", app.Name)
200200
cmd = append(cmd, "--name", app.Name)

pkg/transportrequest/cts/upload_test.go

+22-1
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@
44
package cts
55

66
import (
7+
"testing"
8+
79
"github.com/SAP/jenkins-library/pkg/mock"
810
"github.com/SAP/jenkins-library/pkg/piperutils"
911
"github.com/stretchr/testify/assert"
10-
"testing"
1112
)
1213

1314
func TestUploadCTS(t *testing.T) {
@@ -99,6 +100,26 @@ func TestUploadCTS(t *testing.T) {
99100
assert.Equal(t, []string{"ABAP_USER=me", "ABAP_PASSWORD=******"}, cmd.Env)
100101
}
101102
})
103+
104+
t.Run("fail in case of invalid app name", func(t *testing.T) {
105+
cmd := mock.ShellMockRunner{}
106+
action := UploadAction{
107+
Connection: Connection{Endpoint: "https://example.org:8080/cts", Client: "001", User: "me", Password: "******"},
108+
Application: Application{Pack: "abapPackage", Name: "app Name", Desc: "the Desc"},
109+
Node: Node{
110+
DeployDependencies: []string{},
111+
InstallOpts: []string{},
112+
},
113+
TransportRequestID: "12345678",
114+
ConfigFile: "ui5-deploy.yaml",
115+
DeployUser: "doesNotMatterInThisCase",
116+
}
117+
118+
err := action.Perform(&cmd)
119+
expectedErrorMessge := "application name 'app Name' contains spaces or special characters and is not according to the regex '^[a-zA-Z0-9_]+$'."
120+
121+
assert.EqualErrorf(t, err, expectedErrorMessge, "invalid app name")
122+
})
102123
})
103124

104125
t.Run("config file releated tests", func(t *testing.T) {

0 commit comments

Comments
 (0)