Skip to content

Commit 8c94c76

Browse files
committed
fix: base_output not used if the plugin Output is not a map[string]interface{}
Signed-off-by: Romain Beuque <[email protected]>
1 parent 4a62900 commit 8c94c76

File tree

3 files changed

+34
-4
lines changed

3 files changed

+34
-4
lines changed

engine/engine_test.go

+17
Original file line numberDiff line numberDiff line change
@@ -646,6 +646,23 @@ func TestEmptyStringInput(t *testing.T) {
646646
assert.Equal(t, "", output["foo"])
647647
}
648648

649+
func TestBaseOutputNoOutput(t *testing.T) {
650+
input := map[string]interface{}{}
651+
res, err := createResolution("no-output.yaml", input, nil)
652+
require.NotNil(t, res)
653+
require.Nil(t, err)
654+
655+
res, err = runResolution(res)
656+
657+
require.Nilf(t, err, "got error %s", err)
658+
require.NotNil(t, res)
659+
assert.Equal(t, resolution.StateDone, res.State)
660+
assert.Equal(t, step.StateDone, res.Steps["stepOne"].State)
661+
662+
output := res.Steps["stepOne"].Output.(map[string]interface{})
663+
assert.Equal(t, "buzz", output["foobar"])
664+
}
665+
649666
func TestScriptPlugin(t *testing.T) {
650667
argv := "world"
651668
res, err := createResolution("execScript.yaml", map[string]interface{}{"argv": argv}, nil)

engine/step/step.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -266,13 +266,13 @@ func Run(st *Step, baseConfig map[string]json.RawMessage, values *values.Values,
266266
default:
267267
st.Output, st.Metadata, err = runner.Exec(st.Name, baseCfgRaw, config, ctx)
268268
if baseOutput != nil {
269-
marshaled, err := json.Marshal(st.Output)
270-
if err == nil {
271-
err = utils.JSONnumberUnmarshal(bytes.NewReader(marshaled), &baseOutput)
269+
if st.Output != nil {
270+
marshaled, err := json.Marshal(st.Output)
272271
if err == nil {
273-
st.Output = baseOutput
272+
_ = utils.JSONnumberUnmarshal(bytes.NewReader(marshaled), &baseOutput)
274273
}
275274
}
275+
st.Output = baseOutput
276276
}
277277
st.Payload = st.Output // FIXME deprecate
278278
if err != nil {

engine/templates_tests/no-output.yaml

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
name: no-output
2+
description: A template with step returning no output
3+
title_format: "[test] no output"
4+
auto_runnable: true
5+
steps:
6+
stepOne:
7+
description: first step
8+
idempotent: true
9+
retry_pattern: seconds
10+
action:
11+
type: echo
12+
base_output: {foobar: "buzz"}
13+
configuration: {}

0 commit comments

Comments
 (0)