From 5fed6ca5a943f9af20c8b242b21945093de4e093 Mon Sep 17 00:00:00 2001 From: pk910 Date: Tue, 20 Feb 2024 04:01:45 +0100 Subject: [PATCH] add test id filter to getTestRuns api --- pkg/coordinator/web/api/docs/docs.go | 8 ++++++++ pkg/coordinator/web/api/docs/swagger.json | 8 ++++++++ pkg/coordinator/web/api/docs/swagger.yaml | 5 +++++ pkg/coordinator/web/api/get_test_api.go | 16 ++++++++-------- pkg/coordinator/web/api/get_test_runs_api.go | 7 +++++++ 5 files changed, 36 insertions(+), 8 deletions(-) diff --git a/pkg/coordinator/web/api/docs/docs.go b/pkg/coordinator/web/api/docs/docs.go index 164f8e8..94c340d 100644 --- a/pkg/coordinator/web/api/docs/docs.go +++ b/pkg/coordinator/web/api/docs/docs.go @@ -361,6 +361,14 @@ const docTemplate = `{ ], "summary": "Get list of test runs", "operationId": "getTestRuns", + "parameters": [ + { + "type": "string", + "description": "Return test runs for this test ID only", + "name": "test_id", + "in": "query" + } + ], "responses": { "200": { "description": "Success", diff --git a/pkg/coordinator/web/api/docs/swagger.json b/pkg/coordinator/web/api/docs/swagger.json index ba346bf..2748757 100644 --- a/pkg/coordinator/web/api/docs/swagger.json +++ b/pkg/coordinator/web/api/docs/swagger.json @@ -353,6 +353,14 @@ ], "summary": "Get list of test runs", "operationId": "getTestRuns", + "parameters": [ + { + "type": "string", + "description": "Return test runs for this test ID only", + "name": "test_id", + "in": "query" + } + ], "responses": { "200": { "description": "Success", diff --git a/pkg/coordinator/web/api/docs/swagger.yaml b/pkg/coordinator/web/api/docs/swagger.yaml index 0c6d554..aac5201 100644 --- a/pkg/coordinator/web/api/docs/swagger.yaml +++ b/pkg/coordinator/web/api/docs/swagger.yaml @@ -448,6 +448,11 @@ paths: get: description: Returns a list of all test runs. operationId: getTestRuns + parameters: + - description: Return test runs for this test ID only + in: query + name: test_id + type: string produces: - application/json responses: diff --git a/pkg/coordinator/web/api/get_test_api.go b/pkg/coordinator/web/api/get_test_api.go index 9d0d38c..aa16a6c 100644 --- a/pkg/coordinator/web/api/get_test_api.go +++ b/pkg/coordinator/web/api/get_test_api.go @@ -8,13 +8,13 @@ import ( ) type GetTestResponse struct { - ID string `json:"id"` - Source string `json:"source"` - Name string `json:"name"` - Timeout uint64 `json:"timeout"` - Config map[string]any `json:"config"` - ConfigVars map[string]string `json:"configVars"` - Schedule types.TestSchedule `json:"schedule"` + ID string `json:"id"` + Source string `json:"source"` + Name string `json:"name"` + Timeout uint64 `json:"timeout"` + Config map[string]any `json:"config"` + ConfigVars map[string]string `json:"configVars"` + Schedule *types.TestSchedule `json:"schedule"` } // GetTest godoc @@ -64,6 +64,6 @@ func (ah *APIHandler) GetTest(w http.ResponseWriter, r *http.Request) { Timeout: uint64(testConfig.Timeout.Duration.Seconds()), Config: testConfig.Config, ConfigVars: testConfig.ConfigVars, - Schedule: *testConfig.Schedule, + Schedule: testConfig.Schedule, }) } diff --git a/pkg/coordinator/web/api/get_test_runs_api.go b/pkg/coordinator/web/api/get_test_runs_api.go index bcb6651..82f7a35 100644 --- a/pkg/coordinator/web/api/get_test_runs_api.go +++ b/pkg/coordinator/web/api/get_test_runs_api.go @@ -21,6 +21,7 @@ type GetTestRunsResponse struct { // @Tags TestRun // @Description Returns a list of all test runs. // @Produce json +// @Param test_id query string false "Return test runs for this test ID only" // @Success 200 {object} Response{data=[]GetTestRunsResponse} "Success" // @Failure 400 {object} Response "Failure" // @Failure 500 {object} Response "Server Error" @@ -28,10 +29,16 @@ type GetTestRunsResponse struct { func (ah *APIHandler) GetTestRuns(w http.ResponseWriter, r *http.Request) { w.Header().Set("Content-Type", "application/json") + q := r.URL.Query() + filterTestID := q.Get("test_id") testRuns := []*GetTestRunsResponse{} testInstances := append(ah.coordinator.GetTestHistory(), ah.coordinator.GetTestQueue()...) for _, testInstance := range testInstances { + if filterTestID != "" && filterTestID != testInstance.TestID() { + continue + } + testRun := &GetTestRunsResponse{ RunID: testInstance.RunID(), TestID: testInstance.TestID(),