osbuild2: add support for org.osbuild.dnf.config stage

Add support for a new osbuild stage `org.osbuild.dnf.config`, for
configuring DNF.

Add unit tests for the new stage.

Related to https://github.com/osbuild/osbuild/pull/798.

Signed-off-by: Tomas Hozza <thozza@redhat.com>
This commit is contained in:
Tomas Hozza 2021-09-10 18:23:57 +02:00 committed by Ondřej Budai
parent d9610b97fc
commit 8b623d9463
4 changed files with 75 additions and 0 deletions

View file

@ -0,0 +1,32 @@
package osbuild2
// DNFConfigStageOptions represents persistent DNF configuration.
type DNFConfigStageOptions struct {
// List of DNF variables.
Variables []DNFVariable `json:"variables,omitempty"`
}
func (DNFConfigStageOptions) isStageOptions() {}
// NewDNFConfigStageOptions creates a new DNFConfig Stage options object.
func NewDNFConfigStageOptions(variables []DNFVariable) *DNFConfigStageOptions {
return &DNFConfigStageOptions{
Variables: variables,
}
}
// NewDNFConfigStage creates a new DNFConfig Stage object.
func NewDNFConfigStage(options *DNFConfigStageOptions) *Stage {
return &Stage{
Type: "org.osbuild.dnf.config",
Options: options,
}
}
// DNFVariable represents a single DNF variable.
type DNFVariable struct {
// Name of the variable.
Name string `json:"name"`
// Value of the variable.
Value string `json:"value"`
}

View file

@ -0,0 +1,31 @@
package osbuild2
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestNewDNFConfigStageOptions(t *testing.T) {
variables := []DNFVariable{
{
Name: "release",
Value: "8.4",
},
}
expectedOptions := &DNFConfigStageOptions{
Variables: variables,
}
actualOptions := NewDNFConfigStageOptions(variables)
assert.Equal(t, expectedOptions, actualOptions)
}
func TestNewDNFConfigStage(t *testing.T) {
expectedStage := &Stage{
Type: "org.osbuild.dnf.config",
Options: &DNFConfigStageOptions{},
}
actualStage := NewDNFConfigStage(&DNFConfigStageOptions{})
assert.Equal(t, expectedStage, actualStage)
}

View file

@ -69,6 +69,8 @@ func (stage *Stage) UnmarshalJSON(data []byte) error {
options = new(CloudInitStageOptions)
case "org.osbuild.chrony":
options = new(ChronyStageOptions)
case "org.osbuild.dnf.config":
options = new(DNFConfigStageOptions)
case "org.osbuild.dracut":
options = new(DracutStageOptions)
case "org.osbuild.dracut.conf":

View file

@ -136,6 +136,16 @@ func TestStage_UnmarshalJSON(t *testing.T) {
data: []byte(`{"type":"org.osbuild.chrony","options":{"servers":[{"hostname":"127.0.0.1","minpoll":0,"maxpoll":4,"iburst":true,"prefer":false},{"hostname":"ntp.example.com"}],"leapsectz":""}}`),
},
},
{
name: "dnf-config",
fields: fields{
Type: "org.osbuild.dnf.config",
Options: &DNFConfigStageOptions{},
},
args: args{
data: []byte(`{"type":"org.osbuild.dnf.config","options":{}}`),
},
},
{
name: "dracut",
fields: fields{