osbuild2: add xz stage implementation
Add support for osbuild `org.osbuild.xz` stage. The stage accepts Files inputs. Add unit tests for the added functionality. Signed-off-by: Tomas Hozza <thozza@redhat.com>
This commit is contained in:
parent
8271910051
commit
52ccf1d6ef
5 changed files with 101 additions and 0 deletions
|
|
@ -21,6 +21,9 @@ func NewFilesInputs(references FilesInputReferences) *FilesInputs {
|
||||||
|
|
||||||
// IMPLEMENTED INTERFACES OF STAGES ACCEPTING THIS INPUTS TYPE
|
// IMPLEMENTED INTERFACES OF STAGES ACCEPTING THIS INPUTS TYPE
|
||||||
|
|
||||||
|
// inputs accepted by the XZ stage
|
||||||
|
func (FilesInputs) isXzStageInputs() {}
|
||||||
|
|
||||||
// SPECIFIC INPUT STRUCTURE
|
// SPECIFIC INPUT STRUCTURE
|
||||||
|
|
||||||
type FilesInput struct {
|
type FilesInput struct {
|
||||||
|
|
|
||||||
|
|
@ -132,6 +132,12 @@ func (stage *Stage) UnmarshalJSON(data []byte) error {
|
||||||
case "org.osbuild.qemu":
|
case "org.osbuild.qemu":
|
||||||
options = new(QEMUStageOptions)
|
options = new(QEMUStageOptions)
|
||||||
inputs = new(QEMUStageInputs)
|
inputs = new(QEMUStageInputs)
|
||||||
|
case "org.osbuild.xz":
|
||||||
|
options = new(XzStageOptions)
|
||||||
|
// TODO: Unmarshalling inputs should be moved to a separate method and struct should be determined by its Type
|
||||||
|
// The stage accepts also source input, but we need to rework all inputs first to handle this nicely here.
|
||||||
|
// Only files input is used by the XZ stage at this moment.
|
||||||
|
inputs = new(FilesInputs)
|
||||||
default:
|
default:
|
||||||
return fmt.Errorf("unexpected stage type: %s", rawStage.Type)
|
return fmt.Errorf("unexpected stage type: %s", rawStage.Type)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -589,6 +589,19 @@ func TestStageV2_UnmarshalJSON(t *testing.T) {
|
||||||
data: []byte(`{"type":"org.osbuild.ostree.preptree","options":{"etc_group_members":["wheel"]}}`),
|
data: []byte(`{"type":"org.osbuild.ostree.preptree","options":{"etc_group_members":["wheel"]}}`),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "xz",
|
||||||
|
fields: fields{
|
||||||
|
Type: "org.osbuild.xz",
|
||||||
|
Options: &XzStageOptions{
|
||||||
|
Filename: "image.raw.xz",
|
||||||
|
},
|
||||||
|
Inputs: NewFilesInputs(NewFilesInputReferencesPipeline("os", "image.raw")),
|
||||||
|
},
|
||||||
|
args: args{
|
||||||
|
data: []byte(`{"type":"org.osbuild.xz","inputs":{"file":{"type":"org.osbuild.files","origin":"org.osbuild.pipeline","references":{"name:os":{"file":"image.raw"}}}},"options":{"filename":"image.raw.xz"}}`),
|
||||||
|
},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
for idx, tt := range tests {
|
for idx, tt := range tests {
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
|
|
|
||||||
32
internal/osbuild2/xz_stage.go
Normal file
32
internal/osbuild2/xz_stage.go
Normal file
|
|
@ -0,0 +1,32 @@
|
||||||
|
package osbuild2
|
||||||
|
|
||||||
|
type XzStageOptions struct {
|
||||||
|
// Filename for xz archive
|
||||||
|
Filename string `json:"filename"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (XzStageOptions) isStageOptions() {}
|
||||||
|
|
||||||
|
func NewXzStageOptions(filename string) *XzStageOptions {
|
||||||
|
return &XzStageOptions{
|
||||||
|
Filename: filename,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
type XzStageInputs interface {
|
||||||
|
isXzStageInputs()
|
||||||
|
}
|
||||||
|
|
||||||
|
// Compresses a file into a xz archive.
|
||||||
|
func NewXzStage(options *XzStageOptions, inputs XzStageInputs) *Stage {
|
||||||
|
var stageInputs Inputs
|
||||||
|
if inputs != nil {
|
||||||
|
stageInputs = inputs.(Inputs)
|
||||||
|
}
|
||||||
|
|
||||||
|
return &Stage{
|
||||||
|
Type: "org.osbuild.xz",
|
||||||
|
Options: options,
|
||||||
|
Inputs: stageInputs,
|
||||||
|
}
|
||||||
|
}
|
||||||
47
internal/osbuild2/xz_stage_test.go
Normal file
47
internal/osbuild2/xz_stage_test.go
Normal file
|
|
@ -0,0 +1,47 @@
|
||||||
|
package osbuild2
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestNewXzStageOptions(t *testing.T) {
|
||||||
|
filename := "image.raw.xz"
|
||||||
|
|
||||||
|
expectedOptions := &XzStageOptions{
|
||||||
|
Filename: filename,
|
||||||
|
}
|
||||||
|
|
||||||
|
actualOptions := NewXzStageOptions(filename)
|
||||||
|
assert.Equal(t, expectedOptions, actualOptions)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestNewXzStage(t *testing.T) {
|
||||||
|
inputFilename := "image.raw"
|
||||||
|
filename := "image.raw.xz"
|
||||||
|
pipeline := "os"
|
||||||
|
|
||||||
|
expectedStage := &Stage{
|
||||||
|
Type: "org.osbuild.xz",
|
||||||
|
Options: NewXzStageOptions(filename),
|
||||||
|
Inputs: NewFilesInputs(NewFilesInputReferencesPipeline(pipeline, inputFilename)),
|
||||||
|
}
|
||||||
|
|
||||||
|
actualStage := NewXzStage(NewXzStageOptions(filename),
|
||||||
|
NewFilesInputs(NewFilesInputReferencesPipeline(pipeline, inputFilename)))
|
||||||
|
assert.Equal(t, expectedStage, actualStage)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestNewXzStageNoInputs(t *testing.T) {
|
||||||
|
filename := "image.raw.xz"
|
||||||
|
|
||||||
|
expectedStage := &Stage{
|
||||||
|
Type: "org.osbuild.xz",
|
||||||
|
Options: &XzStageOptions{Filename: filename},
|
||||||
|
Inputs: nil,
|
||||||
|
}
|
||||||
|
|
||||||
|
actualStage := NewXzStage(&XzStageOptions{Filename: filename}, nil)
|
||||||
|
assert.Equal(t, expectedStage, actualStage)
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue