Skip to content

Commit 39341b2

Browse files
committed
Set the CloudEvent ID to match CDEvents Id
When using the CloudEvent binding, the CloudEvent ID must match, according to the specification, with the CDEvents Id. This can be done today by the event producer via the CloudEvents and CDEvents SDKs, however, since it's required by the spec, it's better implemented as default by the CDEvents SDK directly. Fixes: #57 Signed-off-by: Andrea Frittoli <[email protected]>
1 parent b99c57a commit 39341b2

File tree

2 files changed

+4
-0
lines changed

2 files changed

+4
-0
lines changed

pkg/api/bindings.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ func AsCloudEvent(event CDEventReader) (*cloudevents.Event, error) {
9898
return nil, fmt.Errorf("cannot validate CDEvent %v", err)
9999
}
100100
ce := cloudevents.NewEvent()
101+
ce.SetID(event.GetId())
101102
ce.SetSource(event.GetSource())
102103
ce.SetSubject(event.GetSubjectId())
103104
ce.SetType(event.GetType().String())

pkg/api/bindings_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,9 @@ func TestAsCloudEvent(t *testing.T) {
116116
if err != nil {
117117
t.Fatalf("didn't expected it to fail, but it did: %v", err)
118118
}
119+
if d := cmp.Diff(tc.event.GetId(), ce.Context.GetID()); d != "" {
120+
t.Errorf("args: diff(-want,+got):\n%s", d)
121+
}
119122
if d := cmp.Diff(testSubjectId, ce.Context.GetSubject()); d != "" {
120123
t.Errorf("args: diff(-want,+got):\n%s", d)
121124
}

0 commit comments

Comments
 (0)