diff --git a/pkg/blueprint/disk_customizations.go b/pkg/blueprint/disk_customizations.go index 40ecfdab31..0fd360bfb7 100644 --- a/pkg/blueprint/disk_customizations.go +++ b/pkg/blueprint/disk_customizations.go @@ -113,13 +113,15 @@ func (lv *LVCustomization) UnmarshalJSON(data []byte) error { lv.Name = lvAnySize.Name lv.FilesystemTypedCustomization = lvAnySize.FilesystemTypedCustomization - if lvAnySize.MinSize != nil { - size, err := decodeSize(lvAnySize.MinSize) - if err != nil { - return err - } - lv.MinSize = size + if lvAnySize.MinSize == nil { + return fmt.Errorf("minsize is required") + } + size, err := decodeSize(lvAnySize.MinSize) + if err != nil { + return err } + lv.MinSize = size + return nil } @@ -177,14 +179,16 @@ func (v *PartitionCustomization) UnmarshalJSON(data []byte) error { v.Type = partType - if typeSniffer.MinSize != nil { - minsize, err := decodeSize(typeSniffer.MinSize) - if err != nil { - return fmt.Errorf("%s error decoding minsize for partition: %w", errPrefix, err) - } - v.MinSize = minsize + if typeSniffer.MinSize == nil { + return fmt.Errorf("minsize is required") } + minsize, err := decodeSize(typeSniffer.MinSize) + if err != nil { + return fmt.Errorf("%s error decoding minsize for partition: %w", errPrefix, err) + } + v.MinSize = minsize + return nil } @@ -301,13 +305,15 @@ func (v *PartitionCustomization) UnmarshalTOML(data any) error { v.Type = partType - if minsizeField, ok := d["minsize"]; ok { - minsize, err := decodeSize(minsizeField) - if err != nil { - return fmt.Errorf("%s error decoding minsize for partition: %w", errPrefix, err) - } - v.MinSize = minsize + minsizeField, ok := d["minsize"] + if !ok { + return fmt.Errorf("minsize is required") + } + minsize, err := decodeSize(minsizeField) + if err != nil { + return fmt.Errorf("%s error decoding minsize for partition: %w", errPrefix, err) } + v.MinSize = minsize return nil } diff --git a/pkg/blueprint/disk_customizations_test.go b/pkg/blueprint/disk_customizations_test.go index 7a22d8b779..9c3259b5dc 100644 --- a/pkg/blueprint/disk_customizations_test.go +++ b/pkg/blueprint/disk_customizations_test.go @@ -1035,16 +1035,8 @@ func TestPartitionCustomizationUnmarshalJSON(t *testing.T) { testCases := map[string]testCase{ "nothing": { - input: "{}", - expected: &blueprint.PartitionCustomization{ - Type: "plain", - MinSize: 0, - FilesystemTypedCustomization: blueprint.FilesystemTypedCustomization{ - Mountpoint: "", - Label: "", - FSType: "", - }, - }, + input: "{}", + errorMsg: "minsize is required", }, "plain": { input: `{ @@ -1346,16 +1338,8 @@ func TestPartitionCustomizationUnmarshalTOML(t *testing.T) { testCases := map[string]testCase{ "nothing": { - input: "", - expected: &blueprint.PartitionCustomization{ - Type: "plain", - MinSize: 0, - FilesystemTypedCustomization: blueprint.FilesystemTypedCustomization{ - Mountpoint: "", - Label: "", - FSType: "", - }, - }, + input: "", + errorMsg: "toml: line 0: minsize is required", }, "plain": { input: `type = "plain" @@ -1647,13 +1631,6 @@ func TestDiskCustomizationUnmarshalJSON(t *testing.T) { } testCases := map[string]testCase{ - "nothing": { - inputJSON: "{}", - inputTOML: "", - expected: &blueprint.DiskCustomization{ - MinSize: 0, - }, - }, "minsize/int": { inputJSON: `{ "minsize": 1234