-
Notifications
You must be signed in to change notification settings - Fork 5
/
get_tests_api.go
41 lines (34 loc) · 1.06 KB
/
get_tests_api.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package api
import (
"net/http"
)
type GetTestsResponse struct {
ID string `json:"id"`
Source string `json:"source"`
Name string `json:"name"`
}
// GetTests godoc
// @Id getTests
// @Summary Get list of test definitions
// @Tags Test
// @Description Returns the list of test definitions. These test definitions can be used to create new test runs and are supplied via the assertoor configuration.
// @Produce json
// @Success 200 {object} Response{data=[]GetTestsResponse} "Success"
// @Failure 400 {object} Response "Failure"
// @Failure 500 {object} Response "Server Error"
// @Router /api/v1/tests [get]
func (ah *APIHandler) GetTests(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
tests := []*GetTestsResponse{}
for _, testDescr := range ah.coordinator.GetTestDescriptors() {
if testDescr.Err() != nil {
continue
}
tests = append(tests, &GetTestsResponse{
ID: testDescr.ID(),
Source: testDescr.Source(),
Name: testDescr.Config().Name,
})
}
ah.sendOKResponse(w, r.URL.String(), tests)
}