This repository was archived by the owner on Jun 27, 2023. It is now read-only.
MOCK-429: add support for assignable types to Eq matcher#481
Merged
cvgw merged 1 commit intogolang:masterfrom Oct 23, 2020
Merged
MOCK-429: add support for assignable types to Eq matcher#481cvgw merged 1 commit intogolang:masterfrom
cvgw merged 1 commit intogolang:masterfrom
Conversation
Collaborator
|
Hi @GrigoriyMikhalkin, is this PR ready for review? |
Contributor
Author
|
@cvgw Hi! Yep. |
cvgw
reviewed
Oct 16, 2020
| x1Val := reflect.ValueOf(e.x) | ||
| x2Val := reflect.ValueOf(x) | ||
|
|
||
| if x1Val.Type().AssignableTo(x2Val.Type()) { |
Collaborator
There was a problem hiding this comment.
I think for aliased types (type A []string) it doesn't matter, but if we are talking about interfaces I think there may be an issue here.
type Foo interface {
Meow() string
}
type Baz struct {}
func (b Baz) Meow() string {
return "meow"
}
type Boomer interface {
Boom(Foo)
}
func TestBoom(t *testing.T) {
// omitted for brevity
var bazzer Baz = newBazzer()
mockBoomer.EXPECT().Boom(gomock.Eq(bazzer)).Times(1)
var fooer Foo = Foo(bazzer)
mockBoomer.Boom(fooer) // Foo not assignable to Baz
}
Contributor
Author
There was a problem hiding this comment.
But interface isn't a type(it has underlying type instead). Here is script in playground https://play.golang.org/p/AvDmLq8arUK -- hope i correctly understood your concern.
Collaborator
There was a problem hiding this comment.
Ah ok, I think I understand. In the case of an interface the object will be resolved to its underlying type which must be assignable to the expected type. Thanks for the demo!
cvgw
approved these changes
Oct 23, 2020
This was referenced Mar 11, 2021
Closed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
Solution to #429. Adds support for assignable types to
Eqmatcher.