From a186fd4705f233a391e4ff9404d6fe5d8f4eec37 Mon Sep 17 00:00:00 2001 From: "Brian C. Lane" Date: Thu, 20 Jan 2022 14:06:55 -0800 Subject: [PATCH] weldr: Check for missing undo blueprint When the server is restarted the blueprint changes, which are only held in memory, are lost. This checks for missing changes and returns an error. The test is also adjusted for the new error. Related: rhbz#1922845 --- internal/weldr/api.go | 9 +++++++++ internal/weldr/api_test.go | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/internal/weldr/api.go b/internal/weldr/api.go index 92b84b012..43a3cca07 100644 --- a/internal/weldr/api.go +++ b/internal/weldr/api.go @@ -2021,6 +2021,15 @@ func (api *API) blueprintUndoHandler(writer http.ResponseWriter, request *http.R } bp := bpChange.Blueprint + if len(bpChange.Blueprint.Name) == 0 { + errors := responseError{ + ID: "BlueprintsError", + Msg: fmt.Sprintf("no blueprint found for commit %s", commit), + } + statusResponseError(writer, http.StatusBadRequest, errors) + return + } + commitMsg := name + ".toml reverted to commit " + commit err = api.store.PushBlueprint(bp, commitMsg) if err != nil { diff --git a/internal/weldr/api_test.go b/internal/weldr/api_test.go index 0e710f0cc..339097a2c 100644 --- a/internal/weldr/api_test.go +++ b/internal/weldr/api_test.go @@ -629,7 +629,7 @@ func TestOldBlueprintsUndo(t *testing.T) { commit := changes.BlueprintsChanges[0].Changes[2].Commit // Undo a known commit, that is old - test.TestRoute(t, api, true, "POST", "/api/v0/blueprints/undo/test-old-changes/"+commit, ``, http.StatusBadRequest, `{"errors":[{"id":"BlueprintsError", "msg":"empty blueprint name not allowed"}], "status":false}`) + test.TestRoute(t, api, true, "POST", "/api/v0/blueprints/undo/test-old-changes/"+commit, ``, http.StatusBadRequest, `{"errors":[{"id":"BlueprintsError", "msg":"no blueprint found for commit `+commit+`"}], "status":false}`) // Check to make sure the undo is not present (can't undo something not there) test.TestRoute(t, api, true, "GET", "/api/v0/blueprints/changes/test-old-changes", ``, http.StatusOK, `{"blueprints":[{"changes":[{"commit":"","message":"Change tmux version","revision":null,"timestamp":""},{"commit":"","message":"Add tmux package","revision":null,"timestamp":""},{"commit":"","message":"Initial commit","revision":null,"timestamp":""}],"name":"test-old-changes","total":3}],"errors":[],"limit":20,"offset":0}`, ignoreFields...)