Improve document transformation in container executor
Start using yaml utils to prepare documents for function input. Change-Id: I4adf4781d10ff8c23eea4bec4e85f8c5b4769a8b Relates-To: #202 Relates-To: #369
This commit is contained in:
parent
4e7053bfb5
commit
7f040fed97
pkg/phase/executors
@ -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
|
||||
|
@ -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) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user