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

Adapt to backend API changes (#4309)

* Remove legacy logging

* Implement new requests

* Improve Tests

* Adapt tests

* Refactor

* Fix tests
This commit is contained in:
Daniel Mieg 2023-03-31 15:26:38 +02:00 committed by GitHub
parent 81d9a0ac8c
commit 549b32c675
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 160 additions and 185 deletions

View File

@ -14,15 +14,14 @@ import (
var executionLogStringCheckout string
func init() {
executionLog := abaputils.PullEntity{
ToExecutionLog: abaputils.AbapLogs{
Results: []abaputils.LogResults{
{
Index: "1",
Type: "LogEntry",
Description: "S",
Timestamp: "/Date(1644332299000+0000)/",
},
executionLog := abaputils.LogProtocolResults{
Results: []abaputils.LogProtocol{
{
ProtocolLine: 1,
OverviewIndex: 1,
Type: "LogEntry",
Description: "S",
Timestamp: "/Date(1644332299000+0000)/",
},
},
}
@ -55,9 +54,9 @@ func TestCheckoutBranchStep(t *testing.T) {
logResultSuccess := `{"d": { "sc_name": "/DMO/SWC", "status": "S", "to_Log_Overview": { "results": [ { "log_index": 1, "log_name": "Main Import", "type_of_found_issues": "Success", "timestamp": "/Date(1644332299000+0000)/", "to_Log_Protocol": { "results": [ { "log_index": 1, "index_no": "1", "log_name": "", "type": "Info", "descr": "Main import", "timestamp": null, "criticality": 0 } ] } } ] } } }`
client := &abaputils.ClientMock{
BodyList: []string{
`{"d" : [] }`,
`{"d" : ` + executionLogStringCheckout + `}`,
logResultSuccess,
`{"d" : { "EntitySets" : [ "LogOverviews" ] } }`,
`{"d" : { "status" : "S" } }`,
`{"d" : { "status" : "S" } }`,
`{"d" : { "status" : "S" } }`,
@ -84,9 +83,9 @@ func TestCheckoutBranchStep(t *testing.T) {
logResultError := `{"d": { "sc_name": "/DMO/SWC", "status": "S", "to_Log_Overview": { "results": [ { "log_index": 1, "log_name": "Main Import", "type_of_found_issues": "Error", "timestamp": "/Date(1644332299000+0000)/", "to_Log_Protocol": { "results": [ { "log_index": 1, "index_no": "1", "log_name": "", "type": "Info", "descr": "Main import", "timestamp": null, "criticality": 0 } ] } } ] } } }`
client := &abaputils.ClientMock{
BodyList: []string{
`{"d" : [] }`,
`{"d" : ` + executionLogStringCheckout + `}`,
logResultError,
`{"d" : { "EntitySets" : [ "LogOverviews" ] } }`,
`{"d" : { "status" : "E" } }`,
`{"d" : { "status" : "E" } }`,
`{"d" : { "status" : "E" } }`,
@ -123,9 +122,9 @@ func TestCheckoutBranchStep(t *testing.T) {
logResultError := `{"d": { "sc_name": "/DMO/SWC", "status": "S", "to_Log_Overview": { "results": [ { "log_index": 1, "log_name": "Main Import", "type_of_found_issues": "Error", "timestamp": "/Date(1644332299000+0000)/", "to_Log_Protocol": { "results": [ { "log_index": 1, "index_no": "1", "log_name": "", "type": "Info", "descr": "Main import", "timestamp": null, "criticality": 0 } ] } } ] } } }`
client := &abaputils.ClientMock{
BodyList: []string{
`{"d" : [] }`,
`{"d" : ` + executionLogStringCheckout + `}`,
logResultError,
`{"d" : { "EntitySets" : [ "LogOverviews" ] } }`,
`{"d" : { "status" : "E" } }`,
`{"d" : { "status" : "E" } }`,
`{"d" : { "status" : "E" } }`,

View File

@ -16,15 +16,14 @@ import (
var executionLogStringClone string
func init() {
executionLog := abaputils.PullEntity{
ToExecutionLog: abaputils.AbapLogs{
Results: []abaputils.LogResults{
{
Index: "1",
Type: "LogEntry",
Description: "S",
Timestamp: "/Date(1644332299000+0000)/",
},
executionLog := abaputils.LogProtocolResults{
Results: []abaputils.LogProtocol{
{
ProtocolLine: 1,
OverviewIndex: 1,
Type: "LogEntry",
Description: "S",
Timestamp: "/Date(1644332299000+0000)/",
},
},
}
@ -78,16 +77,16 @@ repositories:
logResultSuccess := `{"d": { "sc_name": "/DMO/SWC", "status": "S", "to_Log_Overview": { "results": [ { "log_index": 1, "log_name": "Main Import", "type_of_found_issues": "Success", "timestamp": "/Date(1644332299000+0000)/", "to_Log_Protocol": { "results": [ { "log_index": 1, "index_no": "1", "log_name": "", "type": "Info", "descr": "Main import", "timestamp": null, "criticality": 0 } ] } } ] } } }`
client := &abaputils.ClientMock{
BodyList: []string{
`{"d" : [] }`,
`{"d" : ` + executionLogStringClone + `}`,
logResultSuccess,
`{"d" : { "EntitySets" : [ "LogOverviews" ] } }`,
`{"d" : { "status" : "S" } }`,
`{"d" : { "status" : "R" } }`,
`{"d" : { "status" : "R" } }`,
`{"d" : { "status" : "R" } }`,
`{"d" : [] }`,
`{"d" : ` + executionLogStringClone + `}`,
logResultSuccess,
`{"d" : { "EntitySets" : [ "LogOverviews" ] } }`,
`{"d" : { "status" : "S" } }`,
`{"d" : { "status" : "R" } }`,
`{"d" : { "status" : "R" } }`,
@ -124,9 +123,9 @@ repositories:
logResultSuccess := `{"d": { "sc_name": "/DMO/SWC", "status": "S", "to_Log_Overview": { "results": [ { "log_index": 1, "log_name": "Main Import", "type_of_found_issues": "Success", "timestamp": "/Date(1644332299000+0000)/", "to_Log_Protocol": { "results": [ { "log_index": 1, "index_no": "1", "log_name": "", "type": "Info", "descr": "Main import", "timestamp": null, "criticality": 0 } ] } } ] } } }`
client := &abaputils.ClientMock{
BodyList: []string{
`{"d" : [] }`,
`{"d" : ` + executionLogStringClone + `}`,
logResultSuccess,
`{"d" : { "EntitySets" : [ "LogOverviews" ] } }`,
`{"d" : { "status" : "S" } }`,
`{"d" : { "status" : "R" } }`,
`{"d" : { "status" : "R" } }`,
@ -397,15 +396,15 @@ func TestALreadyCloned(t *testing.T) {
logResultSuccess := `{"d": { "sc_name": "/DMO/SWC", "status": "S", "to_Log_Overview": { "results": [ { "log_index": 1, "log_name": "Main Import", "type_of_found_issues": "Success", "timestamp": "/Date(1644332299000+0000)/", "to_Log_Protocol": { "results": [ { "log_index": 1, "index_no": "1", "log_name": "", "type": "Info", "descr": "Main import", "timestamp": null, "criticality": 0 } ] } } ] } } }`
client := &abaputils.ClientMock{
BodyList: []string{
`{"d" : }`,
`{"d" : ` + executionLogStringClone + `}`,
logResultSuccess,
`{"d" : { "EntitySets" : [ "LogOverviews" ] } }`,
`{"d" : { "status" : "S" } }`,
`{"d" : { "status" : "R" } }`,
`{"d" : { "status" : "R" } }`,
`{"d" : }`,
`{"d" : ` + executionLogStringClone + `}`,
logResultSuccess,
`{"d" : { "EntitySets" : [ "LogOverviews" ] } }`,
`{"d" : { "status" : "S" } }`,
`{"d" : { "status" : "R" } }`,
`{"d" : { "status" : "R" } }`,
@ -479,7 +478,7 @@ func TestALreadyCloned(t *testing.T) {
err := errors.New("Custom Error")
err, _ = handleCloneError(&resp, err, autils.ReturnedConnectionDetailsHTTP, client, repo)
if assert.Error(t, err, "Expected error") {
assert.Equal(t, "Pull of the repository / software component 'Test', commit 'abcd1234' failed on the ABAP system", err.Error(), "Expected different error message")
assert.Equal(t, "Pull of the repository / software component 'Test', commit 'abcd1234' failed on the ABAP system: Request to ABAP System not successful", err.Error(), "Expected different error message")
}
})

View File

@ -16,15 +16,14 @@ var executionLogStringPull string
var logResultErrorPull string
func init() {
executionLog := abaputils.PullEntity{
ToExecutionLog: abaputils.AbapLogs{
Results: []abaputils.LogResults{
{
Index: "1",
Type: "LogEntry",
Description: "S",
Timestamp: "/Date(1644332299000+0000)/",
},
executionLog := abaputils.LogProtocolResults{
Results: []abaputils.LogProtocol{
{
ProtocolLine: 1,
OverviewIndex: 1,
Type: "LogEntry",
Description: "S",
Timestamp: "/Date(1644332299000+0000)/",
},
},
}
@ -57,9 +56,9 @@ func TestPullStep(t *testing.T) {
logResultSuccess := `{"d": { "sc_name": "/DMO/SWC", "status": "S", "to_Log_Overview": { "results": [ { "log_index": 1, "log_name": "Main Import", "type_of_found_issues": "Success", "timestamp": "/Date(1644332299000+0000)/", "to_Log_Protocol": { "results": [ { "log_index": 1, "index_no": "1", "log_name": "", "type": "Info", "descr": "Main import", "timestamp": null, "criticality": 0 } ] } } ] } } }`
client := &abaputils.ClientMock{
BodyList: []string{
`{"d" : [] }`,
`{"d" : ` + executionLogStringPull + `}`,
logResultSuccess,
`{"d" : { "EntitySets" : [ "LogOverviews" ] } }`,
`{"d" : { "status" : "S" } }`,
`{"d" : { "status" : "R" } }`,
`{"d" : { "status" : "R" } }`,
@ -71,6 +70,7 @@ func TestPullStep(t *testing.T) {
err := runAbapEnvironmentPullGitRepo(&config, &autils, client)
assert.NoError(t, err, "Did not expect error")
assert.Equal(t, 0, len(client.BodyList), "Not all requests were done")
})
t.Run("Run Step Failure", func(t *testing.T) {

View File

@ -15,6 +15,9 @@ import (
)
const failureMessageClonePull = "Could not pull the Repository / Software Component "
const numberOfEntriesPerPage = 100
const logOutputStatusLength = 10
const logOutputTimestampLength = 29
// PollEntity periodically polls the pull/import entity to get the status. Check if the import is still running
func PollEntity(repositoryName string, connectionDetails ConnectionDetailsHTTP, client piperhttp.Sender, pollIntervall time.Duration) (string, error) {
@ -30,17 +33,8 @@ func PollEntity(repositoryName string, connectionDetails ConnectionDetailsHTTP,
status = pullEntity.Status
log.Entry().WithField("StatusCode", responseStatus).Info("Status: " + pullEntity.StatusDescription)
if pullEntity.Status != "R" {
printTransportLogs := true
if serviceContainsNewLogEntities(connectionDetails, client) {
PrintLogs(repositoryName, connectionDetails, client)
printTransportLogs = false
}
if pullEntity.Status == "E" {
log.SetErrorCategory(log.ErrorUndefined)
PrintLegacyLogs(repositoryName, connectionDetails, client, true, printTransportLogs)
} else {
PrintLegacyLogs(repositoryName, connectionDetails, client, false, printTransportLogs)
}
PrintLogs(repositoryName, connectionDetails, client)
break
}
time.Sleep(pollIntervall)
@ -48,37 +42,8 @@ func PollEntity(repositoryName string, connectionDetails ConnectionDetailsHTTP,
return status, nil
}
func serviceContainsNewLogEntities(connectionDetails ConnectionDetailsHTTP, client piperhttp.Sender) (newLogEntitiesAvailable bool) {
newLogEntitiesAvailable = false
details := connectionDetails
details.URL = details.Host + "/sap/opu/odata/sap/MANAGE_GIT_REPOSITORY/"
resp, err := GetHTTPResponse("GET", details, nil, client)
if err != nil {
return
}
defer resp.Body.Close()
var entitySet EntitySetsForManageGitRepository
// Parse response
var abapResp map[string]*json.RawMessage
bodyText, _ := ioutil.ReadAll(resp.Body)
json.Unmarshal(bodyText, &abapResp)
json.Unmarshal(*abapResp["d"], &entitySet)
for _, entitySet := range entitySet.EntitySets {
if entitySet == "LogOverviews" || entitySet == "LogProtocols" {
return true
}
}
return
}
func PrintLogs(repositoryName string, connectionDetails ConnectionDetailsHTTP, client piperhttp.Sender) {
connectionDetails.URL = connectionDetails.URL + "?$expand=to_Log_Overview,to_Log_Overview/to_Log_Protocol"
connectionDetails.URL = connectionDetails.URL + "?$expand=to_Log_Overview"
entity, _, err := GetStatus(failureMessageClonePull+repositoryName, connectionDetails, client)
if err != nil {
return
@ -94,127 +59,102 @@ func PrintLogs(repositoryName string, connectionDetails ConnectionDetailsHTTP, c
return entity.ToLogOverview.Results[i].Index < entity.ToLogOverview.Results[j].Index
})
// Get Lengths
phaseLength := 22 // minimum default length
for _, logEntry := range entity.ToLogOverview.Results {
if l := len(logEntry.Name); l > phaseLength {
phaseLength = l
}
}
statusLength := 10
timestampLength := 29
logOutputPhaseLength, logOutputLineLength := calculateLenghts(entity)
// Dashed Line Length
lineLength := 10 + phaseLength + statusLength + timestampLength
printOverview(logOutputLineLength, logOutputPhaseLength, entity)
// Print Overview
log.Entry().Infof("\n")
dashedLine(lineLength)
log.Entry().Infof("| %-"+fmt.Sprint(phaseLength)+"s | %"+fmt.Sprint(statusLength)+"s | %-"+fmt.Sprint(timestampLength)+"s |", "Phase", "Status", "Timestamp")
dashedLine(lineLength)
for _, logEntry := range entity.ToLogOverview.Results {
log.Entry().Infof("| %-"+fmt.Sprint(phaseLength)+"s | %"+fmt.Sprint(statusLength)+"s | %-"+fmt.Sprint(timestampLength)+"s |", logEntry.Name, logEntry.Status, ConvertTime(logEntry.Timestamp))
}
dashedLine(lineLength)
dashedLine(logOutputLineLength)
// Print Details
for _, logEntryForDetails := range entity.ToLogOverview.Results {
printLog(logEntryForDetails)
printLog(logEntryForDetails, connectionDetails, client)
}
log.Entry().Infof("-------------------------")
return
}
func printOverview(logOutputLineLength int, logOutputPhaseLength int, entity PullEntity) {
log.Entry().Infof("\n")
dashedLine(logOutputLineLength)
log.Entry().Infof("| %-"+fmt.Sprint(logOutputPhaseLength)+"s | %"+fmt.Sprint(logOutputStatusLength)+"s | %-"+fmt.Sprint(logOutputTimestampLength)+"s |", "Phase", "Status", "Timestamp")
dashedLine(logOutputLineLength)
for _, logEntry := range entity.ToLogOverview.Results {
log.Entry().Infof("| %-"+fmt.Sprint(logOutputPhaseLength)+"s | %"+fmt.Sprint(logOutputStatusLength)+"s | %-"+fmt.Sprint(logOutputTimestampLength)+"s |", logEntry.Name, logEntry.Status, ConvertTime(logEntry.Timestamp))
}
}
func calculateLenghts(entity PullEntity) (int, int) {
phaseLength := 22
for _, logEntry := range entity.ToLogOverview.Results {
if l := len(logEntry.Name); l > phaseLength {
phaseLength = l
}
}
lineLength := 10 + phaseLength + logOutputStatusLength + logOutputTimestampLength
return phaseLength, lineLength
}
func dashedLine(i int) {
log.Entry().Infof(strings.Repeat("-", i))
}
func printLog(logEntry LogResultsV2) {
func printLog(logEntry LogResultsV2, connectionDetails ConnectionDetailsHTTP, client piperhttp.Sender) {
sort.SliceStable(logEntry.ToLogProtocol.Results, func(i, j int) bool {
return logEntry.ToLogProtocol.Results[i].ProtocolLine < logEntry.ToLogProtocol.Results[j].ProtocolLine
})
readNextLogEntries := true
page := 0
printHeader(logEntry)
for {
query := getLogProtocolQuery(page)
connectionDetails.URL = logEntry.ToLogProtocol.Deferred.URI + query
entity, err := GetProtocol(failureMessageClonePull, connectionDetails, client)
if (err != nil || reflect.DeepEqual(entity, LogProtocolResults{})) {
readNextLogEntries = false
}
sort.SliceStable(entity.Results, func(i, j int) bool {
return entity.Results[i].ProtocolLine < entity.Results[j].ProtocolLine
})
if logEntry.Status != `Success` {
for _, entry := range entity.Results {
log.Entry().Info(entry.Description)
}
} else {
for _, entry := range entity.Results {
log.Entry().Debug(entry.Description)
}
}
page += 1
if !readNextLogEntries {
break
}
}
}
func printHeader(logEntry LogResultsV2) {
if logEntry.Status != `Success` {
log.Entry().Infof("\n")
log.Entry().Infof("-------------------------")
log.Entry().Infof("%s (%v)", logEntry.Name, ConvertTime(logEntry.Timestamp))
log.Entry().Infof("-------------------------")
for _, entry := range logEntry.ToLogProtocol.Results {
log.Entry().Info(entry.Description)
}
} else {
log.Entry().Debugf("\n")
log.Entry().Debugf("-------------------------")
log.Entry().Debugf("%s (%v)", logEntry.Name, ConvertTime(logEntry.Timestamp))
log.Entry().Debugf("-------------------------")
for _, entry := range logEntry.ToLogProtocol.Results {
log.Entry().Debug(entry.Description)
}
}
}
// PrintLegacyLogs sorts and formats the received transport and execution log of an import; Deprecated with SAP BTP, ABAP Environment release 2205
func PrintLegacyLogs(repositoryName string, connectionDetails ConnectionDetailsHTTP, client piperhttp.Sender, errorOnSystem bool, includeTransportLog bool) {
connectionDetails.URL = connectionDetails.URL + "?$expand=to_Transport_log,to_Execution_log"
entity, _, err := GetStatus(failureMessageClonePull+repositoryName, connectionDetails, client)
if err != nil {
return
}
// Sort logs
sort.SliceStable(entity.ToExecutionLog.Results, func(i, j int) bool {
return entity.ToExecutionLog.Results[i].Index < entity.ToExecutionLog.Results[j].Index
})
sort.SliceStable(entity.ToTransportLog.Results, func(i, j int) bool {
return entity.ToTransportLog.Results[i].Index < entity.ToTransportLog.Results[j].Index
})
// Show transport and execution log if either the action was erroenous on the system or the log level is set to "debug" (verbose = true)
if errorOnSystem {
if includeTransportLog {
log.Entry().Info("-------------------------")
log.Entry().Info("Transport Log")
log.Entry().Info("-------------------------")
for _, logEntry := range entity.ToTransportLog.Results {
log.Entry().WithField("Timestamp", ConvertTime(logEntry.Timestamp)).Info(logEntry.Description)
}
}
log.Entry().Info("-------------------------")
log.Entry().Info("Execution Log")
log.Entry().Info("-------------------------")
for _, logEntry := range entity.ToExecutionLog.Results {
log.Entry().WithField("Timestamp", ConvertTime(logEntry.Timestamp)).Info(logEntry.Description)
}
log.Entry().Info("-------------------------")
} else {
if includeTransportLog {
log.Entry().Debug("-------------------------")
log.Entry().Debug("Transport Log")
log.Entry().Debug("-------------------------")
for _, logEntry := range entity.ToTransportLog.Results {
log.Entry().WithField("Timestamp", ConvertTime(logEntry.Timestamp)).Debug(logEntry.Description)
}
}
log.Entry().Debug("-------------------------")
log.Entry().Debug("Execution Log")
log.Entry().Debug("-------------------------")
for _, logEntry := range entity.ToExecutionLog.Results {
log.Entry().WithField("Timestamp", ConvertTime(logEntry.Timestamp)).Debug(logEntry.Description)
}
log.Entry().Debug("-------------------------")
}
func getLogProtocolQuery(page int) string {
skip := page * numberOfEntriesPerPage
top := numberOfEntriesPerPage
return fmt.Sprintf("?$skip=%s&$top=%s", fmt.Sprint(skip), fmt.Sprint(top))
}
func GetStatus(failureMessage string, connectionDetails ConnectionDetailsHTTP, client piperhttp.Sender) (body PullEntity, status string, err error) {
@ -251,6 +191,31 @@ func GetStatus(failureMessage string, connectionDetails ConnectionDetailsHTTP, c
return body, resp.Status, nil
}
func GetProtocol(failureMessage string, connectionDetails ConnectionDetailsHTTP, client piperhttp.Sender) (body LogProtocolResults, err error) {
resp, err := GetHTTPResponse("GET", connectionDetails, nil, client)
if err != nil {
log.SetErrorCategory(log.ErrorInfrastructure)
err = HandleHTTPError(resp, err, failureMessage, connectionDetails)
return body, err
}
defer resp.Body.Close()
// Parse response
var abapResp map[string]*json.RawMessage
bodyText, _ := ioutil.ReadAll(resp.Body)
marshallError := json.Unmarshal(bodyText, &abapResp)
if marshallError != nil {
return body, errors.Wrap(marshallError, "Could not parse response from the ABAP Environment system")
}
marshallError = json.Unmarshal(*abapResp["d"], &body)
if marshallError != nil {
return body, errors.Wrap(marshallError, "Could not parse response from the ABAP Environment system")
}
return body, nil
}
// GetRepositories for parsing one or multiple branches and repositories from repositories file or branchName and repositoryName configuration
func GetRepositories(config *RepositoriesConfig, branchRequired bool) ([]Repository, error) {
var repositories = make([]Repository, 0)
@ -401,12 +366,20 @@ type AbapLogsV2 struct {
}
type LogResultsV2 struct {
Metadata AbapMetadata `json:"__metadata"`
Index int `json:"log_index"`
Name string `json:"log_name"`
Status string `json:"type_of_found_issues"`
Timestamp string `json:"timestamp"`
ToLogProtocol LogProtocolResults `json:"to_Log_Protocol"`
Metadata AbapMetadata `json:"__metadata"`
Index int `json:"log_index"`
Name string `json:"log_name"`
Status string `json:"type_of_found_issues"`
Timestamp string `json:"timestamp"`
ToLogProtocol LogProtocolDeferred `json:"to_Log_Protocol"`
}
type LogProtocolDeferred struct {
Deferred URI `json:"__deferred"`
}
type URI struct {
URI string `json:"uri"`
}
type LogProtocolResults struct {
@ -419,6 +392,7 @@ type LogProtocol struct {
ProtocolLine int `json:"index_no"`
Type string `json:"type"`
Description string `json:"descr"`
Timestamp string `json:"timestamp"`
}
// LogResults struct for Execution and Transport Log entities A4C_A2G_GHA_SC_LOG_EXE and A4C_A2G_GHA_SC_LOG_TP

View File

@ -14,21 +14,22 @@ import (
var executionLogString string
func init() {
executionLog := PullEntity{
ToExecutionLog: AbapLogs{
Results: []LogResults{
{
Index: "1",
Type: "LogEntry",
Description: "S",
Timestamp: "/Date(1644332299000+0000)/",
},
executionLog := LogProtocolResults{
Results: []LogProtocol{
{
ProtocolLine: 1,
OverviewIndex: 1,
Type: "LogEntry",
Description: "S",
Timestamp: "/Date(1644332299000+0000)/",
},
},
}
executionLogResponse, _ := json.Marshal(executionLog)
executionLogString = string(executionLogResponse)
}
func TestPollEntity(t *testing.T) {
t.Run("Test poll entity - success case", func(t *testing.T) {
@ -36,9 +37,9 @@ func TestPollEntity(t *testing.T) {
logResultSuccess := fmt.Sprintf(`{"d": { "sc_name": "/DMO/SWC", "status": "S", "to_Log_Overview": { "results": [ { "log_index": 1, "log_name": "Main Import", "type_of_found_issues": "Success", "timestamp": "/Date(1644332299000+0000)/", "to_Log_Protocol": { "results": [ { "log_index": 1, "index_no": "1", "log_name": "", "type": "Info", "descr": "Main import", "timestamp": null, "criticality": 0 } ] } } ] } } }`)
client := &ClientMock{
BodyList: []string{
`{"d" : [] }`,
`{"d" : ` + executionLogString + `}`,
logResultSuccess,
`{"d" : { "EntitySets" : [ "LogOverviews" ] } }`,
`{"d" : { "status" : "S" } }`,
`{"d" : { "status" : "R" } }`,
},
@ -69,15 +70,16 @@ func TestPollEntity(t *testing.T) {
}
status, _ := PollEntity(config.RepositoryName, con, client, 0)
assert.Equal(t, "S", status)
assert.Equal(t, 0, len(client.BodyList), "Not all requests were done")
})
t.Run("Test poll entity - error case", func(t *testing.T) {
logResultError := fmt.Sprintf(`{"d": { "sc_name": "/DMO/SWC", "status": "S", "to_Log_Overview": { "results": [ { "log_index": 1, "log_name": "Main Import", "type_of_found_issues": "Error", "timestamp": "/Date(1644332299000+0000)/", "to_Log_Protocol": { "results": [ { "log_index": 1, "index_no": "1", "log_name": "", "type": "Info", "descr": "Main import", "timestamp": null, "criticality": 0 } ] } } ] } } }`)
client := &ClientMock{
BodyList: []string{
`{"d" : [] }`,
`{"d" : ` + executionLogString + `}`,
logResultError,
`{"d" : { "EntitySets" : [ "LogOverviews" ] } }`,
`{"d" : { "status" : "E" } }`,
`{"d" : { "status" : "R" } }`,
},
@ -108,6 +110,7 @@ func TestPollEntity(t *testing.T) {
}
status, _ := PollEntity(config.RepositoryName, con, client, 0)
assert.Equal(t, "E", status)
assert.Equal(t, 0, len(client.BodyList), "Not all requests were done")
})
}