Skip to content
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

Add NotBefore function to testsuite.MockCallWrapper #1301

Merged

Conversation

danieljoos
Copy link
Contributor

What was changed

This PR adds a NotBefore method to the testsuite.MockCallWrapper.
It indicates that a mock call must not happen before the given set of other mocks have been called as expected.
The actual functionality for this is already implemented in github.com/stretchr/testify/mock.
The new function forwards to the .NotBefore() method on the wrapped mock object.

Why?

This change further improves the testability of workflows.
It allows to specify the exact sequence that activities and child-workflow executions must happen.
For example, "call activity abc, then execute child-workflow xyz"

Checklist

  1. Closes:
    No issue found.
  2. How was this tested:
    Added an additional unit test.
  3. Any docs updates needed?:
    Go docs should update automatically.

@danieljoos danieljoos requested a review from a team as a code owner November 27, 2023 12:49
@CLAassistant
Copy link

CLAassistant commented Nov 27, 2023

CLA assistant check
All committers have signed the CLA.

@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

// NotBefore indicates that a call to this mock must not happen before the given calls have happened as expected.
// It calls `NotBefore` on the wrapped mock call.
func (c *MockCallWrapper) NotBefore(calls ...*MockCallWrapper) *MockCallWrapper {
wrappedCalls := []*mock.Call{}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Often best practice to create the slice with a certain len/cap if you know what it will be

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense. I've changed the code to create a slice with an initial capacity.

@cretz
Copy link
Member

cretz commented Nov 27, 2023

(will let @Quinn-With-Two-Ns review)

@cretz
Copy link
Member

cretz commented Nov 27, 2023

Thanks! Merged main into branch, will merge into main if/when CI succeeds.

@cretz cretz merged commit 745e948 into temporalio:master Nov 27, 2023
8 checks passed
@danieljoos danieljoos deleted the danieljoos-testsuite-mock-not-before branch November 28, 2023 07:39
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.

4 participants