Skip to content

Commit

Permalink
add test id filter to getTestRuns api
Browse files Browse the repository at this point in the history
  • Loading branch information
pk910 committed Feb 20, 2024
1 parent 22c6021 commit 5fed6ca
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 8 deletions.
8 changes: 8 additions & 0 deletions pkg/coordinator/web/api/docs/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
8 changes: 8 additions & 0 deletions pkg/coordinator/web/api/docs/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
5 changes: 5 additions & 0 deletions pkg/coordinator/web/api/docs/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
16 changes: 8 additions & 8 deletions pkg/coordinator/web/api/get_test_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
})
}
7 changes: 7 additions & 0 deletions pkg/coordinator/web/api/get_test_runs_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,24 @@ 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"
// @Router /api/v1/test_runs [get]
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(),
Expand Down

0 comments on commit 5fed6ca

Please sign in to comment.