Skip to content

Commit

Permalink
fix: interface{} values should be expanded with '%v' (#3659)
Browse files Browse the repository at this point in the history
  • Loading branch information
simster7 authored Aug 3, 2020
1 parent f08ab97 commit 3f293a4
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
2 changes: 1 addition & 1 deletion workflow/controller/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -2487,7 +2487,7 @@ func processItem(fstTmpl *fasttemplate.Template, name string, index int, item wf
mapVal := item.GetMapVal()
for itemKey, itemVal := range mapVal {
replaceMap[fmt.Sprintf("item.%s", itemKey)] = fmt.Sprintf("%v", itemVal)
vals = append(vals, fmt.Sprintf("%s:%s", itemKey, itemVal))
vals = append(vals, fmt.Sprintf("%s:%v", itemKey, itemVal))

}
jsonByteVal, err := json.Marshal(mapVal)
Expand Down
24 changes: 22 additions & 2 deletions workflow/controller/operator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,11 @@ import (
"testing"
"time"

"github.com/argoproj/argo/workflow/controller/cache"

"github.com/prometheus/client_golang/prometheus"
dto "github.com/prometheus/client_model/go"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/valyala/fasttemplate"
apiv1 "k8s.io/api/core/v1"
apierr "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/api/resource"
Expand All @@ -27,6 +26,7 @@ import (
wfv1 "github.com/argoproj/argo/pkg/apis/workflow/v1alpha1"
"github.com/argoproj/argo/test"
"github.com/argoproj/argo/workflow/common"
"github.com/argoproj/argo/workflow/controller/cache"
hydratorfake "github.com/argoproj/argo/workflow/hydrator/fake"
"github.com/argoproj/argo/workflow/util"
)
Expand Down Expand Up @@ -4581,3 +4581,23 @@ func TestFailSuspendedAndPendingNodesAfterShutdown(t *testing.T) {
}
})
}

func TestProcessItem(t *testing.T) {
task := wfv1.DAGTask{
WithParam: `[{"number": 2, "string": "foo", "list": [0, "1"], "json": {"number": 2, "string": "foo", "list": [0, "1"]}}]`,
}
taskBytes, err := json.Marshal(task)
assert.NoError(t, err)
fstTmpl, err := fasttemplate.NewTemplate(string(taskBytes), "{{", "}}")
assert.NoError(t, err)

var items []wfv1.Item
err = json.Unmarshal([]byte(task.WithParam), &items)
assert.NoError(t, err)

var newTask wfv1.DAGTask
newTaskName, err := processItem(fstTmpl, "task-name", 0, items[0], &newTask)
if assert.NoError(t, err) {
assert.Equal(t, `task-name(0:json:map[list:[0 1] number:2 string:foo],list:[0 1],number:2,string:foo)`, newTaskName)
}
}

0 comments on commit 3f293a4

Please sign in to comment.