cloudapi: Simplify the bp.Customizations code

There is a lot of repeated checks for bp.Customization != nil, this
simplifies that by creating an empty blueprint.Customizations at the
top, and checking to see if it is still empty at the bottom and setting
it back to nil.

Includes a new test for calling with an empty (not nil)
v2.Customizations set on the request.
This commit is contained in:
Brian C. Lane 2023-10-11 08:17:06 -07:00 committed by Tomáš Hozza
parent d4af58c9f5
commit ab56a625c4
2 changed files with 35 additions and 112 deletions

View file

@ -20,6 +20,16 @@ func TestGetBlueprintWithCustomizations(t *testing.T) {
assert.Equal(t, "0.0.0", bp.Version)
assert.Nil(t, bp.Customizations)
// Empty request should return empty blueprint
cr = ComposeRequest{
Customizations: &Customizations{},
}
bp, err = cr.GetBlueprintWithCustomizations()
require.Nil(t, err)
assert.Equal(t, "empty blueprint", bp.Name)
assert.Equal(t, "0.0.0", bp.Version)
assert.Nil(t, bp.Customizations)
// Test with customizations
expected := blueprint.Blueprint{Name: "empty blueprint"}
err = expected.Initialize()