Skip to content

Commit

Permalink
fix: base_output not used if the plugin Output is not a map[string]in…
Browse files Browse the repository at this point in the history
…terface{}

Signed-off-by: Romain Beuque <[email protected]>
  • Loading branch information
rbeuque74 committed Mar 23, 2020
1 parent 4a62900 commit 8c94c76
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 4 deletions.
17 changes: 17 additions & 0 deletions engine/engine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -646,6 +646,23 @@ func TestEmptyStringInput(t *testing.T) {
assert.Equal(t, "", output["foo"])
}

func TestBaseOutputNoOutput(t *testing.T) {
input := map[string]interface{}{}
res, err := createResolution("no-output.yaml", input, nil)
require.NotNil(t, res)
require.Nil(t, err)

res, err = runResolution(res)

require.Nilf(t, err, "got error %s", err)
require.NotNil(t, res)
assert.Equal(t, resolution.StateDone, res.State)
assert.Equal(t, step.StateDone, res.Steps["stepOne"].State)

output := res.Steps["stepOne"].Output.(map[string]interface{})
assert.Equal(t, "buzz", output["foobar"])
}

func TestScriptPlugin(t *testing.T) {
argv := "world"
res, err := createResolution("execScript.yaml", map[string]interface{}{"argv": argv}, nil)
Expand Down
8 changes: 4 additions & 4 deletions engine/step/step.go
Original file line number Diff line number Diff line change
Expand Up @@ -266,13 +266,13 @@ func Run(st *Step, baseConfig map[string]json.RawMessage, values *values.Values,
default:
st.Output, st.Metadata, err = runner.Exec(st.Name, baseCfgRaw, config, ctx)
if baseOutput != nil {
marshaled, err := json.Marshal(st.Output)
if err == nil {
err = utils.JSONnumberUnmarshal(bytes.NewReader(marshaled), &baseOutput)
if st.Output != nil {
marshaled, err := json.Marshal(st.Output)
if err == nil {
st.Output = baseOutput
_ = utils.JSONnumberUnmarshal(bytes.NewReader(marshaled), &baseOutput)
}
}
st.Output = baseOutput
}
st.Payload = st.Output // FIXME deprecate
if err != nil {
Expand Down
13 changes: 13 additions & 0 deletions engine/templates_tests/no-output.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
name: no-output
description: A template with step returning no output
title_format: "[test] no output"
auto_runnable: true
steps:
stepOne:
description: first step
idempotent: true
retry_pattern: seconds
action:
type: echo
base_output: {foobar: "buzz"}
configuration: {}

0 comments on commit 8c94c76

Please sign in to comment.