Skip to content

Commit

Permalink
fix: Format issue on WorkflowEventBinding parameters. Fixes #7042 (#7087
Browse files Browse the repository at this point in the history
)

Signed-off-by: Jonathan Robertson <[email protected]>
  • Loading branch information
jrobertson-insite committed Oct 28, 2021
1 parent a498ec9 commit c5de76b
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
2 changes: 1 addition & 1 deletion pkg/apis/workflow/v1alpha1/item.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func (i *Item) String() string {
}

func (i Item) Format(s fmt.State, _ rune) {
_, _ = fmt.Fprintf(s, i.String()) //nolint
_, _ = fmt.Fprintf(s, "%s", i.String()) //nolint
}

func (i Item) MarshalJSON() ([]byte, error) {
Expand Down
1 change: 1 addition & 0 deletions pkg/apis/workflow/v1alpha1/item_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ func TestItem(t *testing.T) {
"3.141": Number,
"true": Bool,
"\"hello\"": String,
"\"hell%test%o\"": String,
"{\"val\":\"123\"}": Map,
"[\"1\",\"2\",\"3\",\"4\",\"5\"]": List,
} {
Expand Down
19 changes: 17 additions & 2 deletions server/event/dispatch/operation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ func TestNewOperation(t *testing.T) {
&wfv1.WorkflowTemplate{
ObjectMeta: metav1.ObjectMeta{Name: "my-wft-3", Namespace: "my-ns"},
},
&wfv1.WorkflowTemplate{
ObjectMeta: metav1.ObjectMeta{Name: "my-wft-4", Namespace: "my-ns", Labels: map[string]string{common.LabelKeyControllerInstanceID: "my-instanceid"}},
},
)
ctx := context.WithValue(context.WithValue(context.Background(), auth.WfKey, client), auth.ClaimsKey, &types.Claims{Claims: jwt.Claims{Subject: "my-sub"}})
recorder := record.NewFakeRecorder(6)
Expand Down Expand Up @@ -147,20 +150,32 @@ func TestNewOperation(t *testing.T) {
},
},
},
}, "my-ns", "my-discriminator", &wfv1.Item{Value: json.RawMessage(`{"foo": {"bar": "baz"}}`)})
// test a bind with a payload and fmt expression
{
ObjectMeta: metav1.ObjectMeta{Name: "my-wfeb-8", Namespace: "my-ns"},
Spec: wfv1.WorkflowEventBindingSpec{
Event: wfv1.Event{Selector: "true"},
Submit: &wfv1.Submit{
WorkflowTemplateRef: wfv1.WorkflowTemplateRef{Name: "my-wft-4"},
Arguments: &wfv1.Arguments{Parameters: []wfv1.Parameter{{Name: "my-param", ValueFrom: &wfv1.ValueFrom{Event: "payload.formatted"}}}},
},
},
},
}, "my-ns", "my-discriminator", &wfv1.Item{Value: json.RawMessage(`{"foo": {"bar": "baz"}, "formatted": "My%Test%"}`)})
assert.NoError(t, err)
err = operation.Dispatch(ctx)
assert.Error(t, err)

expectedParamValues := []string{
`My%Test%`,
"bar",
"bar",
`{"bar":"baz"}`,
}
var paramValues []string
// assert
list, err := client.ArgoprojV1alpha1().Workflows("my-ns").List(ctx, metav1.ListOptions{})
if assert.NoError(t, err) && assert.Len(t, list.Items, 3) {
if assert.NoError(t, err) && assert.Len(t, list.Items, 4) {
for _, wf := range list.Items {
assert.Equal(t, "my-instanceid", wf.Labels[common.LabelKeyControllerInstanceID])
assert.Equal(t, "my-sub", wf.Labels[common.LabelKeyCreator])
Expand Down

0 comments on commit c5de76b

Please sign in to comment.