mirror of
https://github.com/SAP/jenkins-library.git
synced 2024-12-12 10:55:20 +02:00
Improve testability of abap steps (#1876)
* Change to make pollIntervall configurable * Adapt checkout
This commit is contained in:
parent
b8f5fd9b28
commit
766a233c01
@ -72,7 +72,7 @@ func runAbapEnvironmentCheckoutBranch(options *abapEnvironmentCheckoutBranchOpti
|
||||
Password: connectionDetails.Password,
|
||||
}
|
||||
client.SetOptions(clientOptions)
|
||||
pollIntervall := 10 * time.Second
|
||||
pollIntervall := com.GetPollIntervall()
|
||||
|
||||
log.Entry().Infof("Starting to switch branch to branch '%v' on repository '%v'", options.BranchName, options.RepositoryName)
|
||||
log.Entry().Info("--------------------------------")
|
||||
|
@ -73,7 +73,7 @@ func runAbapEnvironmentPullGitRepo(options *abapEnvironmentPullGitRepoOptions, t
|
||||
Password: connectionDetails.Password,
|
||||
}
|
||||
client.SetOptions(clientOptions)
|
||||
pollIntervall := 10 * time.Second
|
||||
pollIntervall := com.GetPollIntervall()
|
||||
|
||||
log.Entry().Infof("Start pulling %v repositories", len(options.RepositoryNames))
|
||||
for _, repositoryName := range options.RepositoryNames {
|
||||
|
@ -33,8 +33,9 @@ func TestStep(t *testing.T) {
|
||||
client := &abaputils.ClientMock{
|
||||
BodyList: []string{
|
||||
`{"d" : { "status" : "S" } }`,
|
||||
`{"d" : { "status" : "S" } }`,
|
||||
`{"d" : { "status" : "S" } }`,
|
||||
`{"d" : { "status" : "R" } }`,
|
||||
`{"d" : { "status" : "R" } }`,
|
||||
`{"d" : { "status" : "R" } }`,
|
||||
},
|
||||
Token: "myToken",
|
||||
StatusCode: 200,
|
||||
|
@ -22,7 +22,8 @@ import (
|
||||
AbapUtils Struct
|
||||
*/
|
||||
type AbapUtils struct {
|
||||
Exec command.ExecRunner
|
||||
Exec command.ExecRunner
|
||||
Intervall time.Duration
|
||||
}
|
||||
|
||||
/*
|
||||
@ -30,6 +31,7 @@ Communication for defining function used for communication
|
||||
*/
|
||||
type Communication interface {
|
||||
GetAbapCommunicationArrangementInfo(options AbapEnvironmentOptions, oDataURL string) (ConnectionDetailsHTTP, error)
|
||||
GetPollIntervall() time.Duration
|
||||
}
|
||||
|
||||
// GetAbapCommunicationArrangementInfo function fetches the communcation arrangement information in SAP CP ABAP Environment
|
||||
@ -105,7 +107,17 @@ func ReadServiceKeyAbapEnvironment(options AbapEnvironmentOptions, c command.Exe
|
||||
return abapServiceKey, nil
|
||||
}
|
||||
|
||||
// GetHTTPResponse returns a HTTP response or its corresponding error
|
||||
/*
|
||||
GetPollIntervall returns the specified intervall from AbapUtils or a default value of 10 seconds
|
||||
*/
|
||||
func (abaputils *AbapUtils) GetPollIntervall() time.Duration {
|
||||
if abaputils.Intervall != 0 {
|
||||
return abaputils.Intervall
|
||||
}
|
||||
return 10 * time.Second
|
||||
}
|
||||
|
||||
// GetHTTPResponse wraps the SendRequest function of piperhttp
|
||||
func GetHTTPResponse(requestType string, connectionDetails ConnectionDetailsHTTP, body []byte, client piperhttp.Sender) (*http.Response, error) {
|
||||
|
||||
header := make(map[string][]string)
|
||||
@ -294,6 +306,11 @@ func (autils *AUtilsMock) GetAbapCommunicationArrangementInfo(options AbapEnviro
|
||||
return autils.ReturnedConnectionDetailsHTTP, autils.ReturnedError
|
||||
}
|
||||
|
||||
// GetPollIntervall mock
|
||||
func (autils *AUtilsMock) GetPollIntervall() time.Duration {
|
||||
return 1 * time.Microsecond
|
||||
}
|
||||
|
||||
// Cleanup to reset AUtilsMock
|
||||
func (autils *AUtilsMock) Cleanup() {
|
||||
autils.ReturnedConnectionDetailsHTTP = ConnectionDetailsHTTP{}
|
||||
|
Loading…
Reference in New Issue
Block a user