Skip to content

Commit

Permalink
osbuild: add partition to osbuild.Mount
Browse files Browse the repository at this point in the history
This commit adds support for the `partition` feature in mounts
that enumerates partitions from loopback devices that use the
`partscan` feature.

See osbuild/osbuild#1501 for the coresponding
osbuild PR.
  • Loading branch information
mvo5 committed Jan 30, 2024
1 parent 726c324 commit 328d3ab
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 5 deletions.
11 changes: 6 additions & 5 deletions pkg/osbuild/mount.go
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
38 changes: 38 additions & 0 deletions pkg/osbuild/mount_test.go
Original file line number Diff line number Diff line change
@@ -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"
)

Expand Down Expand Up @@ -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:])
}

0 comments on commit 328d3ab

Please sign in to comment.