diff --git a/pkg/phase/executors/container.go b/pkg/phase/executors/container.go index f5ede4f32..beafd8d84 100644 --- a/pkg/phase/executors/container.go +++ b/pkg/phase/executors/container.go @@ -35,11 +35,6 @@ import ( "opendev.org/airship/airshipctl/pkg/phase/ifc" ) -const ( - // yamlSeparator uses to separate yaml files - yamlSeparator = "---\n" -) - var _ ifc.Executor = &ContainerExecutor{} // ContainerExecutor contains resources for generic container executor @@ -130,23 +125,14 @@ func (c *ContainerExecutor) Run(evtCh chan events.Event, opts ifc.RunOptions) { // SetInput sets input for function func (c *ContainerExecutor) SetInput(evtCh chan events.Event) { - docs, err := c.ExecutorBundle.GetAllDocuments() + buf := &bytes.Buffer{} + err := c.ExecutorBundle.Write(buf) if err != nil { handleError(evtCh, err) return } - docsBytes := make([]byte, 0) - for _, doc := range docs { - data, err := doc.AsYAML() - if err != nil { - handleError(evtCh, err) - return - } - docsBytes = append(docsBytes, []byte(yamlSeparator)...) - docsBytes = append(docsBytes, data...) - } - c.RunFns.Input = bytes.NewReader(docsBytes) + c.RunFns.Input = buf } // PrepareFunctions prepares data for function diff --git a/pkg/phase/executors/container_test.go b/pkg/phase/executors/container_test.go index 6e0df1aca..075bd504c 100644 --- a/pkg/phase/executors/container_test.go +++ b/pkg/phase/executors/container_test.go @@ -32,6 +32,7 @@ import ( "opendev.org/airship/airshipctl/pkg/phase" "opendev.org/airship/airshipctl/pkg/phase/executors" "opendev.org/airship/airshipctl/pkg/phase/ifc" + yaml_util "opendev.org/airship/airshipctl/pkg/util/yaml" ) const ( @@ -107,7 +108,6 @@ metadata: name: master-0-bmc-secret type: Opaque ` - yamlSeparator = "---\n" ) func TestRegisterContainerExecutor(t *testing.T) { @@ -161,9 +161,12 @@ func TestSetInputSingleDocument(t *testing.T) { require.NoError(t, err) docBytes, err := doc.AsYAML() require.NoError(t, err) - docBytes = append([]byte(yamlSeparator), docBytes...) + buf := &bytes.Buffer{} + buf.Write([]byte(yaml_util.DashYamlSeparator)) + buf.Write(docBytes) + buf.Write([]byte(yaml_util.DotYamlSeparator)) - assert.Equal(t, bytes.NewReader(docBytes), e.RunFns.Input) + assert.Equal(t, buf, e.RunFns.Input) } func TestSetInputManyDocuments(t *testing.T) { @@ -192,16 +195,21 @@ func TestSetInputManyDocuments(t *testing.T) { require.NoError(t, err) docSecondBytes, err := docSecond.AsYAML() require.NoError(t, err) - docBytes := append([]byte(yamlSeparator), docSecondBytes...) + + buf := &bytes.Buffer{} + buf.Write([]byte(yaml_util.DashYamlSeparator)) + buf.Write(docSecondBytes) + buf.Write([]byte(yaml_util.DotYamlSeparator)) docFirst, err := document.NewDocumentFromBytes([]byte(firstDocInput)) require.NoError(t, err) docFirstBytes, err := docFirst.AsYAML() require.NoError(t, err) - docBytes = append(docBytes, []byte(yamlSeparator)...) - docBytes = append(docBytes, docFirstBytes...) + buf.Write([]byte(yaml_util.DashYamlSeparator)) + buf.Write(docFirstBytes) + buf.Write([]byte(yaml_util.DotYamlSeparator)) - assert.Equal(t, bytes.NewReader(docBytes), e.RunFns.Input) + assert.Equal(t, buf, e.RunFns.Input) } func TestPrepareFunctions(t *testing.T) {