osbuild/copy: support files input

Add support for files input in the copy stage. This will enable copying
inline sources as a custom files in the image filesystem tree.

Add a simple unit test covering the use of this stage input.

Signed-off-by: Tomáš Hozza <thozza@redhat.com>
This commit is contained in:
Tomáš Hozza 2023-01-31 12:15:55 +01:00 committed by Sanne Raymaekers
parent b007b0ea12
commit 2e54557cd4
2 changed files with 30 additions and 0 deletions

View file

@ -39,6 +39,10 @@ func NewCopyStageSimple(options *CopyStageOptions, inputs Inputs) *Stage {
}
}
type CopyStageFilesInputs map[string]*FilesInput
func (*CopyStageFilesInputs) isStageInputs() {}
// GenCopyFSTreeOptions creates the options, inputs, devices, and mounts properties
// for an org.osbuild.copy stage for a given source tree using a partition
// table description to define the mounts

View file

@ -1,6 +1,7 @@
package osbuild
import (
"fmt"
"testing"
"github.com/stretchr/testify/assert"
@ -43,3 +44,28 @@ func TestNewCopyStage(t *testing.T) {
actualStage := NewCopyStage(&CopyStageOptions{paths}, NewPipelineTreeInputs("tree-input", "input-pipeline"), &stageDevices, &stageMounts)
assert.Equal(t, expectedStage, actualStage)
}
func TestNewCopyStageSimpleSourcesInputs(t *testing.T) {
fileSum := "1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef"
paths := []CopyStagePath{
{
From: fmt.Sprintf("input://inlinefile/sha256:%x", fileSum),
To: "tree://etc/inlinefile",
},
}
filesInputs := CopyStageFilesInputs{
"inlinefile": NewFilesInput(NewFilesInputSourceArrayRef([]FilesInputSourceArrayRefEntry{
NewFilesInputSourceArrayRefEntry(fileSum, nil),
})),
}
expectedStage := &Stage{
Type: "org.osbuild.copy",
Options: &CopyStageOptions{paths},
Inputs: &filesInputs,
}
actualStage := NewCopyStageSimple(&CopyStageOptions{paths}, &filesInputs)
assert.Equal(t, expectedStage, actualStage)
}