diff --git a/pkg/osbuild/mount.go b/pkg/osbuild/mount.go index 5b9e730387..96a44ae00c 100644 --- a/pkg/osbuild/mount.go +++ b/pkg/osbuild/mount.go @@ -1,11 +1,12 @@ package osbuild type Mount struct { - Name string `json:"name"` - Type string `json:"type"` - Source string `json:"source,omitempty"` - Target string `json:"target,omitempty"` - Options MountOptions `json:"options,omitempty"` + Name string `json:"name"` + Type string `json:"type"` + Source string `json:"source,omitempty"` + Target string `json:"target,omitempty"` + Options MountOptions `json:"options,omitempty"` + Partition *int `json:"partition,omitempty"` } type MountOptions interface { diff --git a/pkg/osbuild/mount_test.go b/pkg/osbuild/mount_test.go index 06e0216ede..6177d35615 100644 --- a/pkg/osbuild/mount_test.go +++ b/pkg/osbuild/mount_test.go @@ -1,10 +1,13 @@ package osbuild_test import ( + "encoding/json" "testing" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + "github.com/osbuild/images/internal/common" "github.com/osbuild/images/pkg/osbuild" ) @@ -55,3 +58,38 @@ func TestNewMounts(t *testing.T) { assert.Equal(expected, actual) } } + +func TestMountJsonAll(t *testing.T) { + mnt := &osbuild.Mount{ + Name: "xfs", + Type: "org.osbuild.xfs", + Source: "/dev/sda4", + Target: "/mnt/xfs", + //TODO: test "Options:" too + Partition: common.ToPtr(1), + } + json, err := json.MarshalIndent(mnt, "", " ") + require.Nil(t, err) + assert.Equal(t, string(json), ` +{ + "name": "xfs", + "type": "org.osbuild.xfs", + "source": "/dev/sda4", + "target": "/mnt/xfs", + "partition": 1 +}`[1:]) +} + +func TestMountJsonOmitEmptyHonored(t *testing.T) { + mnt := &osbuild.Mount{ + Name: "xfs", + Type: "org.osbuild.xfs", + } + json, err := json.MarshalIndent(mnt, "", " ") + require.Nil(t, err) + assert.Equal(t, string(json), ` +{ + "name": "xfs", + "type": "org.osbuild.xfs" +}`[1:]) +}