mirror of
https://gitea.com/gitea/tea.git
synced 2026-10-26 19:11:25 +01:00
fix(run): filter runs by creation time and report unstarted times as null
run list --since/--until compared the start time, which queued runs report as the Unix epoch, so every queued run was dropped. Filter on created_at, stop scanning at the first older run, and report a run's missing start or completion time as null instead of 1970-01-01. Signed-off-by: bircni <bircni@icloud.com>
This commit is contained in:
3 files changed
+68
-31
No files matched your search
@@ -205,35 +205,60 @@ func TestRunFiltersEncodeServerQueriesAndRejectInvalidStatus(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestRunTimeFilteringPaginatesMatchingResults(t *testing.T) {
|
||||
since := time.Date(2028, 1, 1, 0, 0, 0, 0, time.UTC)
|
||||
until := time.Date(2028, 1, 2, 0, 0, 0, 0, time.UTC)
|
||||
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
switch r.URL.Query().Get("page") {
|
||||
case "1":
|
||||
_, _ = w.Write([]byte(`{"workflow_runs":[{"id":1,"started_at":"2027-12-31T00:00:00Z"},{"id":2,"started_at":"2028-01-01T00:00:00Z"}]}`))
|
||||
_, _ = w.Write([]byte(`{"workflow_runs":[{"id":4,"created_at":"2028-01-03T00:00:00Z"},{"id":3,"created_at":"2028-01-01T12:00:00Z"}]}`))
|
||||
case "2":
|
||||
_, _ = w.Write([]byte(`{"workflow_runs":[{"id":3,"started_at":"2028-01-02T00:00:00Z"}]}`))
|
||||
_, _ = w.Write([]byte(`{"workflow_runs":[{"id":2,"created_at":"2028-01-01T00:00:00Z"}]}`))
|
||||
default:
|
||||
_, _ = w.Write([]byte(`{"workflow_runs":[]}`))
|
||||
}
|
||||
}))
|
||||
defer server.Close()
|
||||
service := Actions{Client: transport.New(server.URL, "", false), Repository: "owner/repo"}
|
||||
items, err := service.Runs(context.Background(), RunListOptions{Limit: 1, Page: 2, Since: &since})
|
||||
items, err := service.Runs(context.Background(), RunListOptions{Limit: 1, Page: 2, Until: &until})
|
||||
require.NoError(t, err)
|
||||
require.Len(t, items, 1)
|
||||
require.EqualValues(t, 3, items[0].ID)
|
||||
require.EqualValues(t, 2, items[0].ID)
|
||||
}
|
||||
|
||||
func TestRunTimeFilteringStopsAtScanCap(t *testing.T) {
|
||||
func TestRunTimeFilteringUsesCreationTimeAndStopsAtOlderRuns(t *testing.T) {
|
||||
since := time.Date(2028, 1, 1, 0, 0, 0, 0, time.UTC)
|
||||
pages := 0
|
||||
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
pages++
|
||||
_, _ = w.Write([]byte(`{"workflow_runs":[{"id":1,"started_at":"2027-12-31T00:00:00Z"}]}`))
|
||||
_, _ = w.Write([]byte(`{"workflow_runs":[
|
||||
{"id":3,"status":"queued","created_at":"2028-01-02T00:00:00Z","started_at":"1970-01-01T00:00:00Z","completed_at":"1970-01-01T00:00:00Z"},
|
||||
{"id":2,"status":"completed","created_at":"2028-01-01T00:00:00Z","started_at":"2028-01-01T00:00:05Z","completed_at":"2028-01-01T00:01:00Z"},
|
||||
{"id":1,"status":"completed","created_at":"2027-12-31T00:00:00Z","started_at":"2027-12-31T00:00:05Z"}]}`))
|
||||
}))
|
||||
defer server.Close()
|
||||
service := Actions{Client: transport.New(server.URL, "", false), Repository: "owner/repo"}
|
||||
_, err := service.Runs(context.Background(), RunListOptions{Limit: 1, Page: 1, Since: &since})
|
||||
items, err := service.Runs(context.Background(), RunListOptions{Limit: 30, Page: 1, Since: &since})
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, 1, pages)
|
||||
require.Len(t, items, 2)
|
||||
require.EqualValues(t, 3, items[0].ID)
|
||||
require.Nil(t, items[0].StartedAt)
|
||||
require.Nil(t, items[0].CompletedAt)
|
||||
require.Equal(t, "2028-01-01T00:00:05Z", *items[1].StartedAt)
|
||||
data, err := json.Marshal(items[0])
|
||||
require.NoError(t, err)
|
||||
require.Contains(t, string(data), `"started_at":null,"completed_at":null`)
|
||||
}
|
||||
|
||||
func TestRunTimeFilteringStopsAtScanCap(t *testing.T) {
|
||||
until := time.Date(2028, 1, 1, 0, 0, 0, 0, time.UTC)
|
||||
pages := 0
|
||||
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
pages++
|
||||
_, _ = w.Write([]byte(`{"workflow_runs":[{"id":1,"created_at":"2028-12-31T00:00:00Z"}]}`))
|
||||
}))
|
||||
defer server.Close()
|
||||
service := Actions{Client: transport.New(server.URL, "", false), Repository: "owner/repo"}
|
||||
_, err := service.Runs(context.Background(), RunListOptions{Limit: 1, Page: 1, Until: &until})
|
||||
require.ErrorContains(t, err, "narrow the search")
|
||||
require.Equal(t, maxRunScanPages, pages)
|
||||
}
|
||||
Reference in new issue
Block a user