Skip to content

Commit

Permalink
osbuild: add support for partscan option in org.osbuild.loopback
Browse files Browse the repository at this point in the history
This commit adds support for `partscan` in `org.osbuild.loopback`.

The coresponding osbuild option was added in
osbuild/osbuild#1501
  • Loading branch information
mvo5 committed Feb 8, 2024
1 parent c238717 commit e9f5b31
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
3 changes: 3 additions & 0 deletions pkg/osbuild/loopback_device.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ type LoopbackDeviceOptions struct {

// Lock (bsd lock) the device after opening it
Lock bool `json:"lock,omitempty"`

// Enable partition scanning as an option
Partscan bool `json:"partscan,omitempty"`
}

func (LoopbackDeviceOptions) isDeviceOptions() {}
Expand Down
46 changes: 46 additions & 0 deletions pkg/osbuild/loopback_device_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package osbuild_test

import (
"encoding/json"
"testing"

"github.com/osbuild/images/internal/common"
"github.com/osbuild/images/pkg/osbuild"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

func TestLoopbackDeviceOptionsSerializesAll(t *testing.T) {
dev := osbuild.LoopbackDeviceOptions{
Filename: "foo.disk",
Start: 12345,
Size: 54321,
SectorSize: common.ToPtr(uint64(4096)),
Lock: true,
Partscan: true,
}
json, err := json.MarshalIndent(dev, "", " ")
require.Nil(t, err)
assert.Equal(t, string(json), `
{
"filename": "foo.disk",
"start": 12345,
"size": 54321,
"sector-size": 4096,
"lock": true,
"partscan": true
}`[1:])
}

func TestLoopbackDeviceOptionsSerializesOmitEmptyHonored(t *testing.T) {
dev := osbuild.LoopbackDeviceOptions{
Filename: "foo.disk",
}
json, err := json.MarshalIndent(dev, "", " ")
require.Nil(t, err)
assert.Equal(t, string(json), `
{
"filename": "foo.disk"
}`[1:])
}

0 comments on commit e9f5b31

Please sign in to comment.