mirror of
https://github.com/SAP/jenkins-library.git
synced 2025-03-27 21:49:15 +02:00
Fix uncaught error in ATC Step (#5276)
* Restructure ATC Step * Add test * Add build unit comment
This commit is contained in:
parent
ed6f6a58d2
commit
6ee302e399
@ -22,9 +22,8 @@ import (
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
func abapEnvironmentRunATCCheck(options abapEnvironmentRunATCCheckOptions, telemetryData *telemetry.CustomData) {
|
||||
func abapEnvironmentRunATCCheck(options abapEnvironmentRunATCCheckOptions, _ *telemetry.CustomData) {
|
||||
// Mapping for options
|
||||
subOptions := convertATCOptions(&options)
|
||||
|
||||
c := &command.Command{}
|
||||
c.Stdout(log.Entry().Writer())
|
||||
@ -33,42 +32,51 @@ func abapEnvironmentRunATCCheck(options abapEnvironmentRunATCCheckOptions, telem
|
||||
autils := abaputils.AbapUtils{
|
||||
Exec: c,
|
||||
}
|
||||
var err error
|
||||
|
||||
client := piperhttp.Client{}
|
||||
fileUtils := piperutils.Files{}
|
||||
|
||||
err := runAbapEnvironmentRunATCCheck(autils, client, options, fileUtils)
|
||||
if err != nil {
|
||||
log.Entry().WithError(err).Fatal("step execution failed")
|
||||
}
|
||||
}
|
||||
|
||||
func runAbapEnvironmentRunATCCheck(autils abaputils.AbapUtils, client piperhttp.Client, options abapEnvironmentRunATCCheckOptions, fileUtils piperutils.Files) error {
|
||||
|
||||
var details abaputils.ConnectionDetailsHTTP
|
||||
cookieJar, _ := cookiejar.New(nil)
|
||||
clientOptions := piperhttp.ClientOptions{
|
||||
CookieJar: cookieJar,
|
||||
}
|
||||
client.SetOptions(clientOptions)
|
||||
|
||||
var details abaputils.ConnectionDetailsHTTP
|
||||
// If Host flag is empty read ABAP endpoint from Service Key instead. Otherwise take ABAP system endpoint from config instead
|
||||
if err == nil {
|
||||
details, err = autils.GetAbapCommunicationArrangementInfo(subOptions, "")
|
||||
subOptions := convertATCOptions(&options)
|
||||
details, err := autils.GetAbapCommunicationArrangementInfo(subOptions, "")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
var resp *http.Response
|
||||
// Fetch Xcrsf-Token
|
||||
if err == nil {
|
||||
credentialsOptions := piperhttp.ClientOptions{
|
||||
Username: details.User,
|
||||
Password: details.Password,
|
||||
CookieJar: cookieJar,
|
||||
}
|
||||
client.SetOptions(credentialsOptions)
|
||||
details.XCsrfToken, err = fetchXcsrfToken("GET", details, nil, &client)
|
||||
|
||||
credentialsOptions := piperhttp.ClientOptions{
|
||||
Username: details.User,
|
||||
Password: details.Password,
|
||||
CookieJar: cookieJar,
|
||||
}
|
||||
if err == nil {
|
||||
resp, err = triggerATCRun(options, details, &client)
|
||||
client.SetOptions(credentialsOptions)
|
||||
details.XCsrfToken, err = fetchXcsrfToken("GET", details, nil, &client)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if err == nil {
|
||||
if err = fetchAndPersistATCResults(resp, details, &client, &fileUtils, options.AtcResultsFileName, options.GenerateHTML, options.FailOnSeverity); err != nil {
|
||||
log.Entry().WithError(err).Fatal("step execution failed")
|
||||
}
|
||||
resp, err := triggerATCRun(options, details, &client)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if err = fetchAndPersistATCResults(resp, details, &client, &fileUtils, options.AtcResultsFileName, options.GenerateHTML, options.FailOnSeverity); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
log.Entry().Info("ATC run completed successfully. If there are any results from the respective run they will be listed in the logs above as well as being saved in the output .xml file")
|
||||
return nil
|
||||
}
|
||||
|
||||
func fetchAndPersistATCResults(resp *http.Response, details abaputils.ConnectionDetailsHTTP, client piperhttp.Sender, utils piperutils.FileUtils, atcResultFileName string, generateHTML bool, failOnSeverityLevel string) error {
|
||||
|
@ -9,10 +9,30 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/SAP/jenkins-library/pkg/abaputils"
|
||||
piperhttp "github.com/SAP/jenkins-library/pkg/http"
|
||||
"github.com/SAP/jenkins-library/pkg/mock"
|
||||
"github.com/SAP/jenkins-library/pkg/piperutils"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestCLIFailure(t *testing.T) {
|
||||
t.Run("function error leads to pipeline error", func(t *testing.T) {
|
||||
|
||||
execRunner := &mock.ExecMockRunner{}
|
||||
autils := abaputils.AbapUtils{
|
||||
Exec: execRunner,
|
||||
}
|
||||
options := abapEnvironmentRunATCCheckOptions{}
|
||||
fileUtils := piperutils.Files{}
|
||||
client := piperhttp.Client{}
|
||||
|
||||
err := runAbapEnvironmentRunATCCheck(autils, client, options, fileUtils)
|
||||
|
||||
assert.Error(t, err)
|
||||
|
||||
})
|
||||
}
|
||||
|
||||
func TestHostConfig(t *testing.T) {
|
||||
t.Run("Check Host: ABAP Endpoint", func(t *testing.T) {
|
||||
config := abaputils.AbapEnvironmentOptions{
|
||||
|
Loading…
x
Reference in New Issue
Block a user