Fix panic in AssertExpectations for mocks without expectations #1207
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
Regression was introduced in #1182 (released in v1.7.3) which updated the mock mutex to be a pointer and updated most call sites that check this mutex to initialize if it's not yet, however the
mock.AssertExpectationsForObjects
and thus themockObject.AssertExpectations
did not take this into account which results in a panic. It's common to initialize mocks at the start of a test and then defer asserting expectations for the end of the test regardless of if a mock had expectations set on it or not. This happens in cases where the test mock does not set anyOn()
methods or does not callmockedObject.Test(t)
which would initialize the mutex if it's not set. CallingmockedObject.Test(t)
is a fine workaround, but regardless this is a regression.I added a test case that repro's the issue without the change. I'm happy to update this to be it's own test, but for now, I just left a comment about why it's there.
Changes
Updates the
mock.AssertExpectationsForObjects
to initialize the mutex if it's not created yet.Motivation
Regression introduced in #1182 which causes a panic for previously working test code
Related issues
Closes #1206