-
Notifications
You must be signed in to change notification settings - Fork 5
/
get_test_run_status_api.go
39 lines (32 loc) · 1.09 KB
/
get_test_run_status_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
package api
import (
"net/http"
"strconv"
"github.com/gorilla/mux"
)
// GetTestRunStatus godoc
// @Id getTestRunStatus
// @Summary Get test run status by run ID
// @Tags TestRun
// @Description Returns the run status with given ID.
// @Produce json
// @Param runId path string true "ID of the test run to get the status for"
// @Success 200 {object} Response{data=string} "Success"
// @Failure 400 {object} Response "Failure"
// @Failure 500 {object} Response "Server Error"
// @Router /api/v1/test_run/{runId}/status [get]
func (ah *APIHandler) GetTestRunStatus(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
vars := mux.Vars(r)
runID, err := strconv.ParseUint(vars["runId"], 10, 64)
if err != nil {
ah.sendErrorResponse(w, r.URL.String(), "invalid runId provided", http.StatusBadRequest)
return
}
testInstance := ah.coordinator.GetTestByRunID(runID)
if testInstance == nil {
ah.sendErrorResponse(w, r.URL.String(), "test run not found", http.StatusNotFound)
return
}
ah.sendOKResponse(w, r.URL.String(), string(testInstance.Status()))
}