Skip to content

Commit 5fed6ca

Browse files
committed
add test id filter to getTestRuns api
1 parent 22c6021 commit 5fed6ca

File tree

5 files changed

+36
-8
lines changed

5 files changed

+36
-8
lines changed

pkg/coordinator/web/api/docs/docs.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,14 @@ const docTemplate = `{
361361
],
362362
"summary": "Get list of test runs",
363363
"operationId": "getTestRuns",
364+
"parameters": [
365+
{
366+
"type": "string",
367+
"description": "Return test runs for this test ID only",
368+
"name": "test_id",
369+
"in": "query"
370+
}
371+
],
364372
"responses": {
365373
"200": {
366374
"description": "Success",

pkg/coordinator/web/api/docs/swagger.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,14 @@
353353
],
354354
"summary": "Get list of test runs",
355355
"operationId": "getTestRuns",
356+
"parameters": [
357+
{
358+
"type": "string",
359+
"description": "Return test runs for this test ID only",
360+
"name": "test_id",
361+
"in": "query"
362+
}
363+
],
356364
"responses": {
357365
"200": {
358366
"description": "Success",

pkg/coordinator/web/api/docs/swagger.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -448,6 +448,11 @@ paths:
448448
get:
449449
description: Returns a list of all test runs.
450450
operationId: getTestRuns
451+
parameters:
452+
- description: Return test runs for this test ID only
453+
in: query
454+
name: test_id
455+
type: string
451456
produces:
452457
- application/json
453458
responses:

pkg/coordinator/web/api/get_test_api.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ import (
88
)
99

1010
type GetTestResponse struct {
11-
ID string `json:"id"`
12-
Source string `json:"source"`
13-
Name string `json:"name"`
14-
Timeout uint64 `json:"timeout"`
15-
Config map[string]any `json:"config"`
16-
ConfigVars map[string]string `json:"configVars"`
17-
Schedule types.TestSchedule `json:"schedule"`
11+
ID string `json:"id"`
12+
Source string `json:"source"`
13+
Name string `json:"name"`
14+
Timeout uint64 `json:"timeout"`
15+
Config map[string]any `json:"config"`
16+
ConfigVars map[string]string `json:"configVars"`
17+
Schedule *types.TestSchedule `json:"schedule"`
1818
}
1919

2020
// GetTest godoc
@@ -64,6 +64,6 @@ func (ah *APIHandler) GetTest(w http.ResponseWriter, r *http.Request) {
6464
Timeout: uint64(testConfig.Timeout.Duration.Seconds()),
6565
Config: testConfig.Config,
6666
ConfigVars: testConfig.ConfigVars,
67-
Schedule: *testConfig.Schedule,
67+
Schedule: testConfig.Schedule,
6868
})
6969
}

pkg/coordinator/web/api/get_test_runs_api.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,24 @@ type GetTestRunsResponse struct {
2121
// @Tags TestRun
2222
// @Description Returns a list of all test runs.
2323
// @Produce json
24+
// @Param test_id query string false "Return test runs for this test ID only"
2425
// @Success 200 {object} Response{data=[]GetTestRunsResponse} "Success"
2526
// @Failure 400 {object} Response "Failure"
2627
// @Failure 500 {object} Response "Server Error"
2728
// @Router /api/v1/test_runs [get]
2829
func (ah *APIHandler) GetTestRuns(w http.ResponseWriter, r *http.Request) {
2930
w.Header().Set("Content-Type", "application/json")
3031

32+
q := r.URL.Query()
33+
filterTestID := q.Get("test_id")
3134
testRuns := []*GetTestRunsResponse{}
3235

3336
testInstances := append(ah.coordinator.GetTestHistory(), ah.coordinator.GetTestQueue()...)
3437
for _, testInstance := range testInstances {
38+
if filterTestID != "" && filterTestID != testInstance.TestID() {
39+
continue
40+
}
41+
3542
testRun := &GetTestRunsResponse{
3643
RunID: testInstance.RunID(),
3744
TestID: testInstance.TestID(),

0 commit comments

Comments
 (0)