Skip to content

Commit

Permalink
Set the CloudEvent ID to match CDEvents Id
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
afrittoli committed Jun 26, 2023
1 parent b99c57a commit 39341b2
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 0 deletions.
1 change: 1 addition & 0 deletions pkg/api/bindings.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ func AsCloudEvent(event CDEventReader) (*cloudevents.Event, error) {
return nil, fmt.Errorf("cannot validate CDEvent %v", err)
}
ce := cloudevents.NewEvent()
ce.SetID(event.GetId())
ce.SetSource(event.GetSource())
ce.SetSubject(event.GetSubjectId())
ce.SetType(event.GetType().String())
Expand Down
3 changes: 3 additions & 0 deletions pkg/api/bindings_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,9 @@ func TestAsCloudEvent(t *testing.T) {
if err != nil {
t.Fatalf("didn't expected it to fail, but it did: %v", err)
}
if d := cmp.Diff(tc.event.GetId(), ce.Context.GetID()); d != "" {
t.Errorf("args: diff(-want,+got):\n%s", d)
}
if d := cmp.Diff(testSubjectId, ce.Context.GetSubject()); d != "" {
t.Errorf("args: diff(-want,+got):\n%s", d)
}
Expand Down

0 comments on commit 39341b2

Please sign in to comment.