Skip to content

fix(mock): return failure for invalid expectation objects - #1984

Open
sergioperezcheco wants to merge 1 commit into
stretchr:masterfrom
sergioperezcheco:fix/mock-invalid-expectation-result-20261006
Open

sergioperezcheco wants to merge 1 commit into
stretchr:masterfrom
sergioperezcheco:fix/mock-invalid-expectation-result-20261006

Conversation

@sergioperezcheco

Copy link
Copy Markdown

Summary

Return false from mock.AssertExpectationsForObjects when an object does not implement the expected mock interface.

Changes

Remember failures from the existing invalid-object diagnostic while continuing to check subsequent valid objects. Regression tests exercise invalid references alone and in either position alongside a valid object, plus successful mocks, unmet expectations and an empty list.

Motivation

The diagnostic introduced in #1795 calls Errorf but continues to a final true return when the remaining objects succeed. Code branching on the assertion result therefore observes success after a reported failure. This keeps the existing rejection of mocks passed by value; it does not restore the behavior discussed in #1227 and #1237 or change the early return for unmet expectations.

Related issues

Related to #1795; that merged change is not an issue being closed here.

Validation: the unchanged production code fails the three new invalid-reference cases; the fix passes the complete go test -p 1 -race -count=1 ./... suite and go vet ./... on Go 1.26.4/macOS arm64. Targeted incremental lint also passes. Other Go/OS CI combinations have not been run locally.

Prepared with Hermes Agent using GPT-6.1-sol; no human review is claimed.

Signed-off-by: sergioperezcheco <checo520@outlook.com>
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.

1 participant