From 0b864c43064b5626d9995717df373ab717185461 Mon Sep 17 00:00:00 2001 From: "Brian C. Lane" Date: Fri, 4 Nov 2022 14:52:01 -0700 Subject: [PATCH] store: Add blueprints to the stored changes Previously the blueprint change was only present until a reboot. The change and its version was recorded, but the actual blueprint was not saved. This adds saving the blueprint when it is changed, and loading the old blueprint versions when they are present in the store. No version change is needed, if the blueprint is not present it is loaded as an empty blueprint which was already being detected by checking the length of the Name. This will allow specific blueprint changes to be recalled after a restart of the server. This also includes tests for the new behavior. --- internal/store/json.go | 12 ++-- internal/store/json_test.go | 126 ++++++++++++++++++++++++++++++++++++ 2 files changed, 133 insertions(+), 5 deletions(-) diff --git a/internal/store/json.go b/internal/store/json.go index 096d73334..9815b0170 100644 --- a/internal/store/json.go +++ b/internal/store/json.go @@ -71,11 +71,11 @@ type sourceV0 struct { type sourcesV0 map[string]sourceV0 type changeV0 struct { - Commit string `json:"commit"` - Message string `json:"message"` - Revision *int `json:"revision"` - Timestamp string `json:"timestamp"` - // BUG: We are currently not (un)marshalling the Blueprint field. + Commit string `json:"commit"` + Message string `json:"message"` + Revision *int `json:"revision"` + Timestamp string `json:"timestamp"` + Blueprint blueprint.Blueprint `json:"blueprint"` } type changesV0 map[string]map[string]changeV0 @@ -203,6 +203,7 @@ func newChangesFromV0(changesStruct changesV0) map[string]map[string]blueprint.C Message: change.Message, Revision: change.Revision, Timestamp: change.Timestamp, + Blueprint: change.Blueprint, } } changes[name] = commits @@ -332,6 +333,7 @@ func newChangesV0(changes map[string]map[string]blueprint.Change) changesV0 { Message: change.Message, Revision: change.Revision, Timestamp: change.Timestamp, + Blueprint: change.Blueprint, } } changesStruct[name] = commitsStruct diff --git a/internal/store/json_test.go b/internal/store/json_test.go index 89846a101..03b64e876 100644 --- a/internal/store/json_test.go +++ b/internal/store/json_test.go @@ -699,6 +699,69 @@ func Test_newChangesFromV0(t *testing.T) { }, }, }, + }, + { + name: "Blueprint Changes With Blueprint", + changes: changesV0{ + "test-blueprint-changes-1": { + "4774980638f4162d9909a613c3ccd938e60bb3a9": { + Commit: "4774980638f4162d9909a613c3ccd938e60bb3a9", + Message: "Recipe test-blueprint-changes-1, version 0.1.2 saved.", + Revision: nil, + Timestamp: "2020-07-29T09:52:07Z", + Blueprint: blueprint.Blueprint{ + Name: "test-blueprint-changes-1", + Version: "0.1.2", + }, + }, + "72fdb76b9994bd72770e283bf3a5206756daf497": { + Commit: "72fdb76b9994bd72770e283bf3a5206756daf497", + Message: "Recipe test-blueprint-changes-1, version 0.1.1 saved.", + Revision: nil, + Timestamp: "2020-07-09T13:33:06Z", + Blueprint: blueprint.Blueprint{ + Name: "test-blueprint-changes-1", + Version: "0.1.1", + }, + }, + "79e2043a83637ffdd4db078c6da23deaae09c84b": { + Commit: "79e2043a83637ffdd4db078c6da23deaae09c84b", + Message: "Recipe test-blueprint-changes-1, version 0.0.1 saved.", + Revision: nil, + Timestamp: "2020-07-07T02:57:00Z", + }, + }, + }, + want: map[string]map[string]blueprint.Change{ + "test-blueprint-changes-1": { + "4774980638f4162d9909a613c3ccd938e60bb3a9": { + Commit: "4774980638f4162d9909a613c3ccd938e60bb3a9", + Message: "Recipe test-blueprint-changes-1, version 0.1.2 saved.", + Revision: nil, + Timestamp: "2020-07-29T09:52:07Z", + Blueprint: blueprint.Blueprint{ + Name: "test-blueprint-changes-1", + Version: "0.1.2", + }, + }, + "72fdb76b9994bd72770e283bf3a5206756daf497": { + Commit: "72fdb76b9994bd72770e283bf3a5206756daf497", + Message: "Recipe test-blueprint-changes-1, version 0.1.1 saved.", + Revision: nil, + Timestamp: "2020-07-09T13:33:06Z", + Blueprint: blueprint.Blueprint{ + Name: "test-blueprint-changes-1", + Version: "0.1.1", + }, + }, + "79e2043a83637ffdd4db078c6da23deaae09c84b": { + Commit: "79e2043a83637ffdd4db078c6da23deaae09c84b", + Message: "Recipe test-blueprint-changes-1, version 0.0.1 saved.", + Revision: nil, + Timestamp: "2020-07-07T02:57:00Z", + }, + }, + }, }} for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { @@ -818,6 +881,69 @@ func Test_newChangesV0(t *testing.T) { }, }, }, + { + name: "Blueprint Changes With Blueprint", + changes: map[string]map[string]blueprint.Change{ + "test-blueprint-changes-1": { + "4774980638f4162d9909a613c3ccd938e60bb3a9": { + Commit: "4774980638f4162d9909a613c3ccd938e60bb3a9", + Message: "Recipe test-blueprint-changes-1, version 0.1.2 saved.", + Revision: nil, + Timestamp: "2020-07-29T09:52:07Z", + Blueprint: blueprint.Blueprint{ + Name: "test-blueprint-changes-1", + Version: "0.1.2", + }, + }, + "72fdb76b9994bd72770e283bf3a5206756daf497": { + Commit: "72fdb76b9994bd72770e283bf3a5206756daf497", + Message: "Recipe test-blueprint-changes-1, version 0.1.1 saved.", + Revision: nil, + Timestamp: "2020-07-09T13:33:06Z", + Blueprint: blueprint.Blueprint{ + Name: "test-blueprint-changes-1", + Version: "0.1.1", + }, + }, + "79e2043a83637ffdd4db078c6da23deaae09c84b": { + Commit: "79e2043a83637ffdd4db078c6da23deaae09c84b", + Message: "Recipe test-blueprint-changes-1, version 0.0.1 saved.", + Revision: nil, + Timestamp: "2020-07-07T02:57:00Z", + }, + }, + }, + want: changesV0{ + "test-blueprint-changes-1": { + "4774980638f4162d9909a613c3ccd938e60bb3a9": { + Commit: "4774980638f4162d9909a613c3ccd938e60bb3a9", + Message: "Recipe test-blueprint-changes-1, version 0.1.2 saved.", + Revision: nil, + Timestamp: "2020-07-29T09:52:07Z", + Blueprint: blueprint.Blueprint{ + Name: "test-blueprint-changes-1", + Version: "0.1.2", + }, + }, + "72fdb76b9994bd72770e283bf3a5206756daf497": { + Commit: "72fdb76b9994bd72770e283bf3a5206756daf497", + Message: "Recipe test-blueprint-changes-1, version 0.1.1 saved.", + Revision: nil, + Timestamp: "2020-07-09T13:33:06Z", + Blueprint: blueprint.Blueprint{ + Name: "test-blueprint-changes-1", + Version: "0.1.1", + }, + }, + "79e2043a83637ffdd4db078c6da23deaae09c84b": { + Commit: "79e2043a83637ffdd4db078c6da23deaae09c84b", + Message: "Recipe test-blueprint-changes-1, version 0.0.1 saved.", + Revision: nil, + Timestamp: "2020-07-07T02:57:00Z", + }, + }, + }, + }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) {