From 2e54557cd4d1b55a21f65a908ef360fc53fe75f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Hozza?= Date: Tue, 31 Jan 2023 12:15:55 +0100 Subject: [PATCH] osbuild/copy: support files input MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- internal/osbuild/copy_stage.go | 4 ++++ internal/osbuild/copy_stage_test.go | 26 ++++++++++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/internal/osbuild/copy_stage.go b/internal/osbuild/copy_stage.go index 3c01bec4e..3d3f06f69 100644 --- a/internal/osbuild/copy_stage.go +++ b/internal/osbuild/copy_stage.go @@ -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 diff --git a/internal/osbuild/copy_stage_test.go b/internal/osbuild/copy_stage_test.go index 9a5867a96..94f5c0d36 100644 --- a/internal/osbuild/copy_stage_test.go +++ b/internal/osbuild/copy_stage_test.go @@ -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) +}