Skip to content

Commit

Permalink
blueprint: add test for disk customization min-size
Browse files Browse the repository at this point in the history
The disk customizations min-size setting is not accepting strings
or strings with units. This commit adds a failing test that will
validate the fix.
  • Loading branch information
mvo5 committed Nov 22, 2024
1 parent c559f01 commit 3b3912b
Showing 1 changed file with 51 additions and 1 deletion.
52 changes: 51 additions & 1 deletion pkg/blueprint/disk_customizations_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ import (
"testing"

"github.com/BurntSushi/toml"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/osbuild/images/pkg/blueprint"
"github.com/osbuild/images/pkg/datasizes"
"github.com/osbuild/images/pkg/pathpolicy"
"github.com/stretchr/testify/assert"
)

func TestPartitioningValidation(t *testing.T) {
Expand Down Expand Up @@ -1648,3 +1650,51 @@ func TestPartitionCustomizationUnmarshalTOML(t *testing.T) {
})
}
}

func TestDiskCustomizationUnmarshalJSON(t *testing.T) {
type testCase struct {
input string
expected *blueprint.DiskCustomization
errorMsg string
}

testCases := map[string]testCase{
"nothing": {
input: "{}",
expected: &blueprint.DiskCustomization{
MinSize: 0,
},
},
"minsize/str": {
input: `{
"minsize": "1234"
}`,
expected: &blueprint.DiskCustomization{
MinSize: 1234,
},
},
"minsize/str-with-unit": {
input: `{
"minsize": "1 GiB"
}`,
expected: &blueprint.DiskCustomization{
MinSize: 1 * datasizes.GiB,
},
},
}

for name := range testCases {
tc := testCases[name]
t.Run(name, func(t *testing.T) {
var dc blueprint.DiskCustomization

err := json.Unmarshal([]byte(tc.input), &dc)
if tc.errorMsg == "" {
require.NoError(t, err)
assert.Equal(t, tc.expected, &dc)
} else {
assert.EqualError(t, err, tc.errorMsg)
}
})
}
}

0 comments on commit 3b3912b

Please sign in to comment.