mirror of
https://github.com/coder/coder.git
synced 2025-07-09 11:45:56 +00:00
feat: add all safe experiments to the deployment page (#10276)
* added new option table type for experiments * added tests * fixed go tests * added go test for new param * removing query change * clearing ExperimentsAll * dont mutate ExperimentsAll * added new route for safe experiments * added new route for safe experiments * added test for new route * PR feedback * altered design * alias children
This commit is contained in:
32
coderd/apidoc/docs.go
generated
32
coderd/apidoc/docs.go
generated
@ -587,8 +587,36 @@ const docTemplate = `{
|
||||
"tags": [
|
||||
"General"
|
||||
],
|
||||
"summary": "Get experiments",
|
||||
"operationId": "get-experiments",
|
||||
"summary": "Get enabled experiments",
|
||||
"operationId": "get-enabled-experiments",
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "OK",
|
||||
"schema": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"$ref": "#/definitions/codersdk.Experiment"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/experiments/available": {
|
||||
"get": {
|
||||
"security": [
|
||||
{
|
||||
"CoderSessionToken": []
|
||||
}
|
||||
],
|
||||
"produces": [
|
||||
"application/json"
|
||||
],
|
||||
"tags": [
|
||||
"General"
|
||||
],
|
||||
"summary": "Get safe experiments",
|
||||
"operationId": "get-safe-experiments",
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "OK",
|
||||
|
28
coderd/apidoc/swagger.json
generated
28
coderd/apidoc/swagger.json
generated
@ -497,8 +497,32 @@
|
||||
],
|
||||
"produces": ["application/json"],
|
||||
"tags": ["General"],
|
||||
"summary": "Get experiments",
|
||||
"operationId": "get-experiments",
|
||||
"summary": "Get enabled experiments",
|
||||
"operationId": "get-enabled-experiments",
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "OK",
|
||||
"schema": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"$ref": "#/definitions/codersdk.Experiment"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/experiments/available": {
|
||||
"get": {
|
||||
"security": [
|
||||
{
|
||||
"CoderSessionToken": []
|
||||
}
|
||||
],
|
||||
"produces": ["application/json"],
|
||||
"tags": ["General"],
|
||||
"summary": "Get safe experiments",
|
||||
"operationId": "get-safe-experiments",
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "OK",
|
||||
|
@ -597,6 +597,7 @@ func New(options *Options) *API {
|
||||
})
|
||||
r.Route("/experiments", func(r chi.Router) {
|
||||
r.Use(apiKeyMiddleware)
|
||||
r.Get("/available", handleExperimentsSafe)
|
||||
r.Get("/", api.handleExperimentsGet)
|
||||
})
|
||||
r.Get("/updatecheck", api.updateCheck)
|
||||
|
@ -4,10 +4,11 @@ import (
|
||||
"net/http"
|
||||
|
||||
"github.com/coder/coder/v2/coderd/httpapi"
|
||||
"github.com/coder/coder/v2/codersdk"
|
||||
)
|
||||
|
||||
// @Summary Get experiments
|
||||
// @ID get-experiments
|
||||
// @Summary Get enabled experiments
|
||||
// @ID get-enabled-experiments
|
||||
// @Security CoderSessionToken
|
||||
// @Produce json
|
||||
// @Tags General
|
||||
@ -17,3 +18,17 @@ func (api *API) handleExperimentsGet(rw http.ResponseWriter, r *http.Request) {
|
||||
ctx := r.Context()
|
||||
httpapi.Write(ctx, rw, http.StatusOK, api.Experiments)
|
||||
}
|
||||
|
||||
// @Summary Get safe experiments
|
||||
// @ID get-safe-experiments
|
||||
// @Security CoderSessionToken
|
||||
// @Produce json
|
||||
// @Tags General
|
||||
// @Success 200 {array} codersdk.Experiment
|
||||
// @Router /experiments/available [get]
|
||||
func handleExperimentsSafe(rw http.ResponseWriter, r *http.Request) {
|
||||
ctx := r.Context()
|
||||
httpapi.Write(ctx, rw, http.StatusOK, codersdk.AvailableExperiments{
|
||||
Safe: codersdk.ExperimentsAll,
|
||||
})
|
||||
}
|
||||
|
@ -116,4 +116,21 @@ func Test_Experiments(t *testing.T) {
|
||||
require.Error(t, err)
|
||||
require.ErrorContains(t, err, httpmw.SignedOutErrorMessage)
|
||||
})
|
||||
|
||||
t.Run("available experiments", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
cfg := coderdtest.DeploymentValues(t)
|
||||
client := coderdtest.New(t, &coderdtest.Options{
|
||||
DeploymentValues: cfg,
|
||||
})
|
||||
_ = coderdtest.CreateFirstUser(t, client)
|
||||
|
||||
ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitLong)
|
||||
defer cancel()
|
||||
|
||||
experiments, err := client.SafeExperiments(ctx)
|
||||
require.NoError(t, err)
|
||||
require.NotNil(t, experiments)
|
||||
require.ElementsMatch(t, codersdk.ExperimentsAll, experiments.Safe)
|
||||
})
|
||||
}
|
||||
|
Reference in New Issue
Block a user