osbuild: rework XZ stage inputs
The `FilesInputs` was since the beginning an XZ-specific implementation of the input, but it was implemented in the `files_input.go` in a false hope that it could be used as a generic stage inputs by any stages. It turned out that various stages require different implementation of its input. Specifically there is usually a stage-specific key, which has assigned a common input type. For XZ stage, the key is `file`. Remove `FilesInputs` and instead implement `XzStageInputs` which is now accepted by the XZ stage. Fix all affected pipeline implementations that use XZ stage. Signed-off-by: Tomáš Hozza <thozza@redhat.com>
This commit is contained in:
parent
413538a18e
commit
dd59ce6a16
6 changed files with 16 additions and 56 deletions
|
|
@ -64,7 +64,7 @@ func (p *CoreOSISOTree) serialize() osbuild.Pipeline {
|
|||
},
|
||||
},
|
||||
},
|
||||
osbuild.NewFilesInputs(osbuild.NewFilesInputPipelineObjectRef(p.payloadPipeline.Name(), p.payloadPipeline.Filename, nil)),
|
||||
osbuild.NewXzStageInputs(osbuild.NewFilesInputPipelineObjectRef(p.payloadPipeline.Name(), p.payloadPipeline.Filename, nil)),
|
||||
))
|
||||
|
||||
if p.coiPipeline.Ignition != nil {
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ func (p *XZ) serialize() osbuild.Pipeline {
|
|||
|
||||
pipeline.AddStage(osbuild.NewXzStage(
|
||||
osbuild.NewXzStageOptions(p.Filename),
|
||||
osbuild.NewFilesInputs(osbuild.NewFilesInputPipelineObjectRef(p.imgPipeline.Name(), p.imgPipeline.Export().Filename(), nil)),
|
||||
osbuild.NewXzStageInputs(osbuild.NewFilesInputPipelineObjectRef(p.imgPipeline.Name(), p.imgPipeline.Export().Filename(), nil)),
|
||||
))
|
||||
|
||||
return pipeline
|
||||
|
|
|
|||
|
|
@ -5,25 +5,6 @@ import (
|
|||
"fmt"
|
||||
)
|
||||
|
||||
// Inputs for individual files
|
||||
|
||||
type FilesInputs struct {
|
||||
File *FilesInput `json:"file"`
|
||||
}
|
||||
|
||||
func (FilesInputs) isStageInputs() {}
|
||||
|
||||
func NewFilesInputs(references FilesInputRef) *FilesInputs {
|
||||
return &FilesInputs{
|
||||
File: NewFilesInput(references),
|
||||
}
|
||||
}
|
||||
|
||||
// IMPLEMENTED INTERFACES OF STAGES ACCEPTING THIS INPUTS TYPE
|
||||
|
||||
// inputs accepted by the XZ stage
|
||||
func (FilesInputs) isXzStageInputs() {}
|
||||
|
||||
// SPECIFIC INPUT STRUCTURE
|
||||
|
||||
type FilesInput struct {
|
||||
|
|
|
|||
|
|
@ -2,40 +2,11 @@ package osbuild
|
|||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
type fakeFilesInputRef struct{}
|
||||
|
||||
func (f *fakeFilesInputRef) isFilesInputRef() {}
|
||||
|
||||
func TestNewFilesInputs(t *testing.T) {
|
||||
inputFilename := "image.raw"
|
||||
pipeline := "os"
|
||||
|
||||
expectedInput := &FilesInputs{
|
||||
File: &FilesInput{
|
||||
inputCommon: inputCommon{
|
||||
Type: InputTypeFiles,
|
||||
Origin: InputOriginPipeline,
|
||||
},
|
||||
References: &FilesInputPipelineObjectRef{
|
||||
fmt.Sprintf("name:%s", pipeline): FilesInputPipelineOptions{File: inputFilename},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
actualInput := NewFilesInputs(NewFilesInputPipelineObjectRef(pipeline, inputFilename, nil))
|
||||
assert.Equal(t, expectedInput, actualInput)
|
||||
|
||||
assert.Panics(t, func() {
|
||||
NewFilesInputs(&fakeFilesInputRef{})
|
||||
})
|
||||
}
|
||||
|
||||
func TestFilesInput_UnmarshalJSON(t *testing.T) {
|
||||
testCases := []struct {
|
||||
name string
|
||||
|
|
|
|||
|
|
@ -13,15 +13,23 @@ func NewXzStageOptions(filename string) *XzStageOptions {
|
|||
}
|
||||
}
|
||||
|
||||
type XzStageInputs interface {
|
||||
isXzStageInputs()
|
||||
type XzStageInputs struct {
|
||||
File *FilesInput `json:"file"`
|
||||
}
|
||||
|
||||
func (*XzStageInputs) isStageInputs() {}
|
||||
|
||||
func NewXzStageInputs(references FilesInputRef) *XzStageInputs {
|
||||
return &XzStageInputs{
|
||||
File: NewFilesInput(references),
|
||||
}
|
||||
}
|
||||
|
||||
// Compresses a file into a xz archive.
|
||||
func NewXzStage(options *XzStageOptions, inputs XzStageInputs) *Stage {
|
||||
func NewXzStage(options *XzStageOptions, inputs *XzStageInputs) *Stage {
|
||||
var stageInputs Inputs
|
||||
if inputs != nil {
|
||||
stageInputs = inputs.(Inputs)
|
||||
stageInputs = inputs
|
||||
}
|
||||
|
||||
return &Stage{
|
||||
|
|
|
|||
|
|
@ -25,11 +25,11 @@ func TestNewXzStage(t *testing.T) {
|
|||
expectedStage := &Stage{
|
||||
Type: "org.osbuild.xz",
|
||||
Options: NewXzStageOptions(filename),
|
||||
Inputs: NewFilesInputs(NewFilesInputPipelineObjectRef(pipeline, inputFilename, nil)),
|
||||
Inputs: NewXzStageInputs(NewFilesInputPipelineObjectRef(pipeline, inputFilename, nil)),
|
||||
}
|
||||
|
||||
actualStage := NewXzStage(NewXzStageOptions(filename),
|
||||
NewFilesInputs(NewFilesInputPipelineObjectRef(pipeline, inputFilename, nil)))
|
||||
NewXzStageInputs(NewFilesInputPipelineObjectRef(pipeline, inputFilename, nil)))
|
||||
assert.Equal(t, expectedStage, actualStage)
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue