Skip to content

Commit

Permalink
Merge branch 'main' into mcobbett-galasa-home-passed-correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
techcobweb committed Aug 27, 2024
2 parents b2d751b + 06a819d commit 7657f07
Show file tree
Hide file tree
Showing 3 changed files with 163 additions and 130 deletions.
6 changes: 0 additions & 6 deletions pkg/runs/runsDownload_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
"net/http"
"net/http/httptest"
"os"
"strconv"
"strings"
"testing"
"time"
Expand Down Expand Up @@ -237,10 +236,7 @@ func WriteMockRasRunsResponse(
writer.Header().Set("Content-Type", "application/json")

values := req.URL.Query()
pageRequestedStr := values.Get("page")
runNameQueryParameter := values.Get("runname")
pageRequested, _ := strconv.Atoi(pageRequestedStr)
assert.Equal(t, pageRequested, 1)

assert.Equal(t, runNameQueryParameter, runName)

Expand All @@ -254,9 +250,7 @@ func WriteMockRasRunsResponse(

writer.Write([]byte(fmt.Sprintf(`
{
"pageNumber": 1,
"pageSize": 1,
"numPages": 1,
"amountOfRuns": %d,
"runs":[ %s ]
}`, len(runResultStrings), combinedRunResultStrings)))
Expand Down
12 changes: 8 additions & 4 deletions pkg/runs/runsGet.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ func GetRunsFromRestApi(
var pageNumberWanted int32 = 1
gotAllResults := false
var restApiVersion string
var pageCursor string

restApiVersion, err = embedded.GetGalasactlRestApiVersion()

Expand All @@ -232,7 +233,7 @@ func GetRunsFromRestApi(
var runData *galasaapi.RunResults
var httpResponse *http.Response
log.Printf("Requesting page '%d' ", pageNumberWanted)
apicall := apiClient.ResultArchiveStoreAPIApi.GetRasSearchRuns(context).ClientApiVersion(restApiVersion)
apicall := apiClient.ResultArchiveStoreAPIApi.GetRasSearchRuns(context).ClientApiVersion(restApiVersion).IncludeCursor("true")
if fromAgeMins != 0 {
apicall = apicall.From(fromTime)
}
Expand All @@ -251,8 +252,10 @@ func GetRunsFromRestApi(
if shouldGetActive {
apicall = apicall.Status(activeStatusNames)
}
apicall = apicall.Page(pageNumberWanted)
apicall = apicall.Sort("to:desc")
if pageCursor != "" {
apicall = apicall.Cursor(pageCursor)
}
apicall = apicall.Sort("from:desc")
runData, httpResponse, err = apicall.Execute()

if err != nil {
Expand All @@ -271,9 +274,10 @@ func GetRunsFromRestApi(
results = append(results, runsOnThisPage...)

// Have we processed the last page ?
if pageNumberWanted == runData.GetNumPages() {
if !runData.HasNextCursor() || len(runsOnThisPage) < int(runData.GetPageSize()) {
gotAllResults = true
} else {
pageCursor = runData.GetNextCursor()
pageNumberWanted++
}
}
Expand Down
Loading

0 comments on commit 7657f07

Please sign in to comment.