diff --git a/pkg/apis/workflow/v1alpha1/item.go b/pkg/apis/workflow/v1alpha1/item.go index a006682828ab..35e53c31fdb2 100644 --- a/pkg/apis/workflow/v1alpha1/item.go +++ b/pkg/apis/workflow/v1alpha1/item.go @@ -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) { diff --git a/pkg/apis/workflow/v1alpha1/item_test.go b/pkg/apis/workflow/v1alpha1/item_test.go index a08ce6d7adb3..5b523ec94f11 100644 --- a/pkg/apis/workflow/v1alpha1/item_test.go +++ b/pkg/apis/workflow/v1alpha1/item_test.go @@ -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, } { diff --git a/server/event/dispatch/operation_test.go b/server/event/dispatch/operation_test.go index 3a7edfe8b7c4..4cffe71a8888 100644 --- a/server/event/dispatch/operation_test.go +++ b/server/event/dispatch/operation_test.go @@ -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) @@ -147,12 +150,24 @@ 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"}`, @@ -160,7 +175,7 @@ func TestNewOperation(t *testing.T) { 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])