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
This commit is contained in:
Brian C. Lane 2022-01-20 14:06:55 -08:00 committed by Ondřej Budai
parent aa8cf41ac2
commit a186fd4705
2 changed files with 10 additions and 1 deletions

View file

@ -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 {

View file

@ -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...)