1
0
mirror of https://github.com/SAP/jenkins-library.git synced 2025-02-21 19:48:53 +02:00

Bug Fixes for abaputils class + unit tests (#2525)

* Bug Fixes

* remove command.Command

Co-authored-by: Daniel Mieg <56156797+DanielMieg@users.noreply.github.com>
This commit is contained in:
Dominik Lendle 2021-01-26 20:23:59 +01:00 committed by GitHub
parent ea203a2c69
commit 52722c298a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 10 deletions

View File

@ -99,7 +99,7 @@ func ReadServiceKeyAbapEnvironment(options AbapEnvironmentOptions, c command.Exe
// parse
json.Unmarshal([]byte(serviceKeyJSON), &abapServiceKey)
if abapServiceKey == (AbapServiceKey{}) {
return abapServiceKey, errors.New("Parsing the service key failed")
return abapServiceKey, errors.New("Parsing the service key failed. Service key is empty")
}
log.Entry().Info("Service Key read successfully")

View File

@ -8,7 +8,6 @@ import (
"os"
"testing"
"github.com/SAP/jenkins-library/pkg/command"
"github.com/SAP/jenkins-library/pkg/log"
"github.com/SAP/jenkins-library/pkg/mock"
"github.com/pkg/errors"
@ -33,7 +32,7 @@ func TestCloudFoundryGetAbapCommunicationInfo(t *testing.T) {
var connectionDetails ConnectionDetailsHTTP
var err error
var autils = AbapUtils{
Exec: &command.Command{},
Exec: &mock.ExecMockRunner{},
}
connectionDetails, err = autils.GetAbapCommunicationArrangementInfo(options, "")
@ -44,10 +43,8 @@ func TestCloudFoundryGetAbapCommunicationInfo(t *testing.T) {
assert.Equal(t, "", connectionDetails.XCsrfToken)
assert.EqualError(t, err, "Parameters missing. Please provide EITHER the Host of the ABAP server OR the Cloud Foundry ApiEndpoint, Organization, Space, Service Instance and a corresponding Service Key for the Communication Scenario SAP_COM_0510")
assert.Error(t, err)
})
t.Run("CF GetAbapCommunicationArrangementInfo - Error - reading service Key", func(t *testing.T) {
//given
options := AbapEnvironmentOptions{
CfAPIEndpoint: "https://api.endpoint.com",
@ -63,7 +60,7 @@ func TestCloudFoundryGetAbapCommunicationInfo(t *testing.T) {
var connectionDetails ConnectionDetailsHTTP
var err error
var autils = AbapUtils{
Exec: &command.Command{},
Exec: &mock.ExecMockRunner{},
}
connectionDetails, err = autils.GetAbapCommunicationArrangementInfo(options, "")
@ -73,7 +70,7 @@ func TestCloudFoundryGetAbapCommunicationInfo(t *testing.T) {
assert.Equal(t, "", connectionDetails.Password)
assert.Equal(t, "", connectionDetails.XCsrfToken)
assert.Error(t, err)
assert.EqualError(t, err, "Read service key failed: Parsing the service key failed. Service key is empty")
})
t.Run("CF GetAbapCommunicationArrangementInfo - Success", func(t *testing.T) {
@ -196,7 +193,6 @@ func TestHostGetAbapCommunicationInfo(t *testing.T) {
func TestReadServiceKeyAbapEnvironment(t *testing.T) {
t.Run("CF ReadServiceKeyAbapEnvironment - Failed to login to Cloud Foundry", func(t *testing.T) {
//given .
options := AbapEnvironmentOptions{
Username: "testUser",
@ -211,7 +207,7 @@ func TestReadServiceKeyAbapEnvironment(t *testing.T) {
//when
var abapKey AbapServiceKey
var err error
abapKey, err = ReadServiceKeyAbapEnvironment(options, &command.Command{})
abapKey, err = ReadServiceKeyAbapEnvironment(options, &mock.ExecMockRunner{})
//then
assert.Equal(t, "", abapKey.Abap.Password)
@ -227,7 +223,7 @@ func TestReadServiceKeyAbapEnvironment(t *testing.T) {
assert.Equal(t, "", abapKey.SystemID)
assert.Equal(t, "", abapKey.URL)
assert.Error(t, err)
assert.EqualError(t, err, "Parsing the service key failed. Service key is empty")
})
}