Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: interface{} values should be expanded with '%v' #3659

Merged
merged 1 commit into from
Aug 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
}
}