From bfe5f981a8aa8653394e8a576dea3a60cba34f93 Mon Sep 17 00:00:00 2001 From: Adam Luzsi Date: Thu, 12 Aug 2021 00:17:58 +0200 Subject: [PATCH] E2E testing related improvements for release rollout rest API --- domains/release/Rollout.go | 6 +++--- .../httpapi/ReleaseRolloutController.go | 20 ++++++++++--------- .../httpapi/ReleaseRolloutController_test.go | 6 ++++-- .../interface/httpintf/swagger/swagger.json | 16 +++++++-------- 4 files changed, 26 insertions(+), 22 deletions(-) diff --git a/domains/release/Rollout.go b/domains/release/Rollout.go index 2f4a825..499a404 100644 --- a/domains/release/Rollout.go +++ b/domains/release/Rollout.go @@ -16,9 +16,9 @@ import ( type Rollout struct { ID string `ext:"ID"` // FlagID is the release flag id to which the rolloutBase belongs - FlagID string + FlagID string `json:"flag_id"` // EnvironmentID is the deployment environment id - DeploymentEnvironmentID string + DeploymentEnvironmentID string `json:"env_id"` // Plan holds the composited rule set about the pilot participation decision logic. Plan RolloutDefinition `json:"plan,omitempty"` } @@ -538,7 +538,7 @@ type rolloutView struct { // FlagID is the release flag id to which the rolloutBase belongs FlagID string `json:"flag_id"` // EnvironmentID is the deployment environment id - DeploymentEnvironmentID string `json:"deployment_environment_id"` + DeploymentEnvironmentID string `json:"env_id"` // Plan holds the composited rule set about the pilot participation decision logic. RolloutPlan RolloutDefinitionView `json:"plan"` } diff --git a/external/interface/httpintf/httpapi/ReleaseRolloutController.go b/external/interface/httpintf/httpapi/ReleaseRolloutController.go index a6af067..ec44e49 100644 --- a/external/interface/httpintf/httpapi/ReleaseRolloutController.go +++ b/external/interface/httpintf/httpapi/ReleaseRolloutController.go @@ -3,6 +3,7 @@ package httpapi import ( "context" "encoding/json" + "fmt" "net/http" "github.com/adamluzsi/frameless/iterators" @@ -56,9 +57,9 @@ type CreateReleaseRolloutRequest struct { // required: true // in: body Body struct { - EnvironmentID string `json:"envID"` - FlagID string `json:"flagID"` - Rollout struct { + Rollout struct { + EnvironmentID string `json:"env_id"` + FlagID string `json:"flag_id"` // Plan holds the composited rule set about the pilot participation decision logic. // // required: true @@ -108,9 +109,7 @@ func (ctrl ReleaseRolloutController) Create(w http.ResponseWriter, r *http.Reque defer r.Body.Close() // ignorable type Payload struct { - Rollout release.Rollout `json:"rollout"` - EnvironmentID string `json:"envID"` - FlagID string `json:"flagID"` + Rollout release.Rollout `json:"rollout"` } var p Payload @@ -118,10 +117,13 @@ func (ctrl ReleaseRolloutController) Create(w http.ResponseWriter, r *http.Reque return } - p.Rollout.FlagID = p.FlagID - p.Rollout.DeploymentEnvironmentID = p.EnvironmentID + rr := p.Rollout + ctx := r.Context() + rrs := ctrl.UseCases.Storage.ReleaseRollout(ctx) + err := rrs.Create(ctx, &rr) - if ctrl.handleFlagValidationError(w, ctrl.UseCases.Storage.ReleaseRollout(r.Context()).Create(r.Context(), &p.Rollout)) { + if ctrl.handleFlagValidationError(w, err) { + fmt.Println(`????`, err, fmt.Sprintf("%#v", rr)) return } diff --git a/external/interface/httpintf/httpapi/ReleaseRolloutController_test.go b/external/interface/httpintf/httpapi/ReleaseRolloutController_test.go index 2992a4c..2596053 100644 --- a/external/interface/httpintf/httpapi/ReleaseRolloutController_test.go +++ b/external/interface/httpintf/httpapi/ReleaseRolloutController_test.go @@ -130,13 +130,15 @@ func SpecReleaseRolloutControllerCreate(s *testcase.Spec) { return &r }) + Debug(s) + Body.Let(s, func(t *testcase.T) interface{} { r := sh.GetReleaseRollout(t, rollout.Name) var req httpapi.CreateReleaseRolloutRequest t.Log(r) req.Body.Rollout.Plan = release.RolloutDefinitionView{Definition: r.Plan} - req.Body.EnvironmentID = sh.ExampleDeploymentEnvironment(t).ID - req.Body.FlagID = sh.ExampleReleaseFlag(t).ID + req.Body.Rollout.EnvironmentID = sh.ExampleDeploymentEnvironment(t).ID + req.Body.Rollout.FlagID = sh.ExampleReleaseFlag(t).ID return req.Body }) diff --git a/external/interface/httpintf/swagger/swagger.json b/external/interface/httpintf/swagger/swagger.json index 714e84a..8d57f65 100644 --- a/external/interface/httpintf/swagger/swagger.json +++ b/external/interface/httpintf/swagger/swagger.json @@ -663,20 +663,20 @@ "schema": { "type": "object", "properties": { - "envID": { - "type": "string", - "x-go-name": "EnvironmentID" - }, - "flagID": { - "type": "string", - "x-go-name": "FlagID" - }, "rollout": { "type": "object", "required": [ "plan" ], "properties": { + "env_id": { + "type": "string", + "x-go-name": "EnvironmentID" + }, + "flag_id": { + "type": "string", + "x-go-name": "FlagID" + }, "plan": { "description": "Plan holds the composited rule set about the pilot participation decision logic.", "type": "object",