@@ -22,9 +22,8 @@ import (
2222 "github.com/pkg/errors"
2323)
2424
25- func abapEnvironmentRunATCCheck (options abapEnvironmentRunATCCheckOptions , telemetryData * telemetry.CustomData ) {
25+ func abapEnvironmentRunATCCheck (options abapEnvironmentRunATCCheckOptions , _ * telemetry.CustomData ) {
2626 // Mapping for options
27- subOptions := convertATCOptions (& options )
2827
2928 c := & command.Command {}
3029 c .Stdout (log .Entry ().Writer ())
@@ -33,42 +32,51 @@ func abapEnvironmentRunATCCheck(options abapEnvironmentRunATCCheckOptions, telem
3332 autils := abaputils.AbapUtils {
3433 Exec : c ,
3534 }
36- var err error
3735
3836 client := piperhttp.Client {}
3937 fileUtils := piperutils.Files {}
38+
39+ err := runAbapEnvironmentRunATCCheck (autils , client , options , fileUtils )
40+ if err != nil {
41+ log .Entry ().WithError (err ).Fatal ("step execution failed" )
42+ }
43+ }
44+
45+ func runAbapEnvironmentRunATCCheck (autils abaputils.AbapUtils , client piperhttp.Client , options abapEnvironmentRunATCCheckOptions , fileUtils piperutils.Files ) error {
46+
47+ var details abaputils.ConnectionDetailsHTTP
4048 cookieJar , _ := cookiejar .New (nil )
4149 clientOptions := piperhttp.ClientOptions {
4250 CookieJar : cookieJar ,
4351 }
4452 client .SetOptions (clientOptions )
4553
46- var details abaputils. ConnectionDetailsHTTP
47- // If Host flag is empty read ABAP endpoint from Service Key instead. Otherwise take ABAP system endpoint from config instead
48- if err = = nil {
49- details , err = autils . GetAbapCommunicationArrangementInfo ( subOptions , "" )
54+ subOptions := convertATCOptions ( & options )
55+ details , err := autils . GetAbapCommunicationArrangementInfo ( subOptions , "" )
56+ if err ! = nil {
57+ return err
5058 }
51- var resp * http.Response
52- // Fetch Xcrsf-Token
53- if err == nil {
54- credentialsOptions := piperhttp.ClientOptions {
55- Username : details .User ,
56- Password : details .Password ,
57- CookieJar : cookieJar ,
58- }
59- client .SetOptions (credentialsOptions )
60- details .XCsrfToken , err = fetchXcsrfToken ("GET" , details , nil , & client )
59+
60+ credentialsOptions := piperhttp.ClientOptions {
61+ Username : details .User ,
62+ Password : details .Password ,
63+ CookieJar : cookieJar ,
6164 }
62- if err == nil {
63- resp , err = triggerATCRun (options , details , & client )
65+ client .SetOptions (credentialsOptions )
66+ details .XCsrfToken , err = fetchXcsrfToken ("GET" , details , nil , & client )
67+ if err != nil {
68+ return err
6469 }
65- if err == nil {
66- if err = fetchAndPersistATCResults (resp , details , & client , & fileUtils , options .AtcResultsFileName , options .GenerateHTML , options .FailOnSeverity ); err != nil {
67- log .Entry ().WithError (err ).Fatal ("step execution failed" )
68- }
70+ resp , err := triggerATCRun (options , details , & client )
71+ if err != nil {
72+ return err
73+ }
74+ if err = fetchAndPersistATCResults (resp , details , & client , & fileUtils , options .AtcResultsFileName , options .GenerateHTML , options .FailOnSeverity ); err != nil {
75+ return err
6976 }
7077
7178 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" )
79+ return nil
7280}
7381
7482func fetchAndPersistATCResults (resp * http.Response , details abaputils.ConnectionDetailsHTTP , client piperhttp.Sender , utils piperutils.FileUtils , atcResultFileName string , generateHTML bool , failOnSeverityLevel string ) error {
0 commit comments