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.
This commit is contained in:
Brian C. Lane 2022-11-04 14:52:01 -07:00 committed by Ondřej Budai
parent 088ca6ec72
commit 0b864c4306
2 changed files with 133 additions and 5 deletions

View file

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

View file

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