Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

osbuild: add new osbuild.NewOSTreeDeploymentMountDefault() #563

Merged
merged 1 commit into from
Apr 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 28 additions & 2 deletions pkg/osbuild/ostree_deployment_mount.go
Original file line number Diff line number Diff line change
@@ -1,20 +1,33 @@
package osbuild

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

type OSTreeMountSource string

const (
OSTreeMountSourceTree OSTreeMountSource = "tree"
OSTreeMountSourceMount OSTreeMountSource = "mount"
)

type OSTreeMountOptions struct {
Source OSTreeMountSource `json:"source,omitempty"`
Deployment OSTreeMountDeployment `json:"deployment"`
}

func (OSTreeMountOptions) isMountOptions() {}

type OSTreeMountDeployment struct {
// Name of the stateroot to be used in the deployment
OSName string `json:"osname"`
OSName string `json:"osname,omitempty"`

// OStree ref to create and use for deployment
Ref string `json:"ref"`
Ref string `json:"ref,omitempty"`

// The deployment serial (usually '0')
Serial *int `json:"serial,omitempty"`

// When set the OSName/Ref/Serial is detected automatically
Default *bool `json:"default,omitempty"`
}

func NewOSTreeDeploymentMount(name, osName, ref string, serial int) *Mount {
Expand All @@ -30,3 +43,16 @@ func NewOSTreeDeploymentMount(name, osName, ref string, serial int) *Mount {
},
}
}

func NewOSTreeDeploymentMountDefault(name string, source OSTreeMountSource) *Mount {
return &Mount{
Type: "org.osbuild.ostree.deployment",
Name: name,
Options: &OSTreeMountOptions{
Source: source,
Deployment: OSTreeMountDeployment{
Default: common.ToPtr(true),
},
},
}
}
46 changes: 46 additions & 0 deletions pkg/osbuild/ostree_deployment_mount_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/pkg/osbuild"

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

func TestOSTreeMountDeploymentDefaultSerialized(t *testing.T) {
mntStage := osbuild.NewOSTreeDeploymentMountDefault("some-name", osbuild.OSTreeMountSourceMount)
json, err := json.MarshalIndent(mntStage, "", " ")
require.Nil(t, err)
assert.Equal(t, string(json), `
{
"name": "some-name",
"type": "org.osbuild.ostree.deployment",
"options": {
"source": "mount",
"deployment": {
"default": true
}
}
}`[1:])
}

func TestOSTreeMountDeploymentSerialized(t *testing.T) {
mntStage := osbuild.NewOSTreeDeploymentMount("some-name", "some-osname", "some-ref", 0)
json, err := json.MarshalIndent(mntStage, "", " ")
require.Nil(t, err)
assert.Equal(t, string(json), `
{
"name": "some-name",
"type": "org.osbuild.ostree.deployment",
"options": {
"deployment": {
"osname": "some-osname",
"ref": "some-ref",
"serial": 0
}
}
}`[1:])
}
Loading