-
Notifications
You must be signed in to change notification settings - Fork 124
/
select.go
76 lines (68 loc) · 2.59 KB
/
select.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package route
import (
"context"
"encoding/json"
"io"
"net/http"
"github.com/evergreen-ci/gimlet"
"github.com/evergreen-ci/utility"
"github.com/mongodb/grip"
"github.com/pkg/errors"
)
type selectTestsHandler struct {
selectTests SelectTestsRequest
}
// SelectTestsRequest represents a request to return a filtered set of tests to
// run. It deliberately includes information that could be looked up in the
// database in order to bypass database lookups. This allows Evergreen to pass
// this information directly to the test selector.
type SelectTestsRequest struct {
// Project is the project identifier.
Project string `json:"project" bson:"project"`
// Requester is the Evergreen requester type.
Requester string `json:"requester" bson:"requester"`
// BuildVariant is the Evergreen build variant.
BuildVariant string `json:"build_variant" bson:"build_variant"`
// TaskID is the Evergreen task ID.
TaskID string `json:"task_id" bson:"task_id"`
// TaskName is the Evergreen task name.
TaskName string `json:"task_name" bson:"task_name"`
// Tests is a list of test names.
Tests []string `json:"tests" bson:"tests"`
}
func makeSelectTestsHandler() gimlet.RouteHandler {
return &selectTestsHandler{}
}
// Factory creates an instance of the handler.
//
// @Summary Select tests
// @Description Return a subset of tests to run for a given task. This endpoint is not yet ready. Please do not use it.
// @Tags select
// @Router /select/tests [post]
// @Param {object} body SelectTestsRequest true "Select tests request"
// @Security Api-User || Api-Key
func (t *selectTestsHandler) Factory() gimlet.RouteHandler {
return &selectTestsHandler{}
}
func (t *selectTestsHandler) Parse(ctx context.Context, r *http.Request) error {
body := utility.NewRequestReader(r)
defer body.Close()
b, err := io.ReadAll(body)
if err != nil {
return errors.Wrap(err, "reading request body")
}
if err = json.Unmarshal(b, &t.selectTests); err != nil {
return errors.Wrap(err, "parsing request body")
}
catcher := grip.NewBasicCatcher()
catcher.NewWhen(t.selectTests.Project == "", "project is required")
catcher.NewWhen(t.selectTests.Requester == "", "requester is required")
catcher.NewWhen(t.selectTests.BuildVariant == "", "build variant is required")
catcher.NewWhen(t.selectTests.TaskID == "", "task ID is required")
catcher.NewWhen(t.selectTests.TaskName == "", "task name is required")
catcher.NewWhen(len(t.selectTests.Tests) == 0, "tests array must not be empty")
return catcher.Resolve()
}
func (t *selectTestsHandler) Run(ctx context.Context) gimlet.Responder {
return gimlet.NewJSONResponse(t.selectTests)
}