Skip to content

Commit

Permalink
fix: add missing return value for error (#5146)
Browse files Browse the repository at this point in the history
  • Loading branch information
srinikitha09 authored Oct 15, 2024
1 parent bc8225c commit bd8b08b
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
2 changes: 1 addition & 1 deletion pkg/transportrequest/cts/upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ func getFioriDeployStatement(
if len(app.Name) > 0 {
re := regexp.MustCompile(pattern)
if !re.MatchString(app.Name) {
fmt.Errorf("application name '%s' contains spaces or special characters. It is not according to the '%s'", app.Name, pattern)
return "", fmt.Errorf("application name '%s' contains spaces or special characters and is not according to the regex '%s'.", app.Name, pattern)
}
log.Entry().Debugf("application name '%s' used from piper config", app.Name)
cmd = append(cmd, "--name", app.Name)
Expand Down
23 changes: 22 additions & 1 deletion pkg/transportrequest/cts/upload_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@
package cts

import (
"testing"

"github.com/SAP/jenkins-library/pkg/mock"
"github.com/SAP/jenkins-library/pkg/piperutils"
"github.com/stretchr/testify/assert"
"testing"
)

func TestUploadCTS(t *testing.T) {
Expand Down Expand Up @@ -99,6 +100,26 @@ func TestUploadCTS(t *testing.T) {
assert.Equal(t, []string{"ABAP_USER=me", "ABAP_PASSWORD=******"}, cmd.Env)
}
})

t.Run("fail in case of invalid app name", func(t *testing.T) {
cmd := mock.ShellMockRunner{}
action := UploadAction{
Connection: Connection{Endpoint: "https://example.org:8080/cts", Client: "001", User: "me", Password: "******"},
Application: Application{Pack: "abapPackage", Name: "app Name", Desc: "the Desc"},
Node: Node{
DeployDependencies: []string{},
InstallOpts: []string{},
},
TransportRequestID: "12345678",
ConfigFile: "ui5-deploy.yaml",
DeployUser: "doesNotMatterInThisCase",
}

err := action.Perform(&cmd)
expectedErrorMessge := "application name 'app Name' contains spaces or special characters and is not according to the regex '^[a-zA-Z0-9_]+$'."

assert.EqualErrorf(t, err, expectedErrorMessge, "invalid app name")
})
})

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

0 comments on commit bd8b08b

Please sign in to comment.