Skip to content

Refactor MockCloudEvent generation to include partial #146

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

Merged
merged 4 commits into from
May 18, 2022

Conversation

TheIronDev
Copy link
Contributor

Description

The goal of this commit is to incorporate the user's partial into the generated CloudEvent.

All the AbstractFactories for Partial Cloud Events now return Cloud Events, and they all
incorporate the user provided partial when creating the Mock Cloud Event..

Theres a few key benefits to this:

  1. Type safety. The Partial Factories were not providing all the necessary fields required (as is the nature of the Partial)
  2. Consistency with other fields. Eg: If a user updates the bucket for storage event, lets try to update the other fields too.
  3. Opaque fields - If we want the user provided partial to take precedence, we can easily control that. (see PubSub and EventArc factories)
  4. Easier to handle one-off behavior. Not all the events behave the same way, particularly with PubSub.

Although this is a "larger" change, the end-user contract remains intact.

This does fix several bugs. Output is different for PubSub, EventArc, and Storage.

@TheIronDev TheIronDev requested a review from inlined May 12, 2022 21:26
The goal of this commit is to incorporate the user's partial into the generated CloudEvent.

All the AbstractFactories for Partial Cloud Events now return Cloud Events, and they all
incorporate the user provided partial when creating the Mock Cloud Event..

Theres a few key benefits to this:

1. Type safety. The Partial Factories were not providing all the necessary fields required (as is the nature of the Partial)
1. Consistency with other fields. Eg: If a user updates the bucket for storage event, lets try to update the other fields too.
1. Opaque fields - If we want the user provided partial to take precedence, we can easily control that. (see PubSub and EventArc factories)
1. Easier to handle one-off behavior. Not all the events behave the same way, particularly with PubSub.

Although this is a "larger" change, the end-user contract remains intact.

This does fix several bugs. Output is different for PubSub, EventArc, and Storage.
@TheIronDev TheIronDev requested a review from colerogers May 17, 2022 21:19
@TheIronDev TheIronDev merged commit 05054d2 into master May 18, 2022
@TheIronDev
Copy link
Contributor Author

Generated CloudEvents will use user-provided Partial to infer other fields.

  • For storage events, updating the Partial's bucket will update:
    • data.bucket
    • Parts of source, data.selfLink, data.id
  • For PubSub events, updating the Partial's data.message.json will:
    • generate a new base64 string for data.message.data
      • (But a user-provided data.message.data still takes priority)

If you called the wrap handler with {bucket: 'bucket2'}...

Previously the returned CloudEvent would look like:

{
  bucket: 'bucket2',
  data: {
    bucket: 'bucket', // 'bucket' because the user never explicitly overwrote it
    // ...
  },
  // ...
}

With this PR, it will look like:

{
  bucket: 'bucket2',
  data: {
    bucket: 'bucket2', // inferred from the bucket
    // ...
  },
  // ...
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants