You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
That didn't work. It turned out that the slice elements are values and their GetName method is only defined for pointers. Go can call it anyway, but Gomega can't (or doesn't). Perhaps it should also support that?
Here's a reproducer:
package gomegatest
import (
"testing"
"github.com/onsi/gomega"
)
type pointerobject struct {
name string
}
func (p *pointerobject) GetName() string {
return p.name
}
type valueobject struct {
name string
}
func (v valueobject) GetName() string {
return v.name
}
type object interface {
GetName() string
}
var _ object = valueobject{}
// Only pointer implements object interface, not value.
var _ object = &pointerobject{}
// var _ object = pointerobject{}
func TestConsistsOf(t *testing.T) {
g := gomega.NewGomegaWithT(t)
e := gomega.ConsistOf(gomega.HaveField("GetName()", gomega.Equal("A")), gomega.HaveField("GetName()", gomega.Equal("B")))
g.Expect([]valueobject{{"A"}, {"B"}}).To(e) // works
g.Expect([]pointerobject{{"A"}, {"B"}}).To(e) // fails
}
The text was updated successfully, but these errors were encountered:
thediveo
added a commit
to thediveo/gomega
that referenced
this issue
Dec 6, 2024
looking into the matcher code base that was originally deliberate; if there is no reason why we should keep this restriction then there's a PR. Yeah, I've just run into this myself 😀
I recently suggested replacing these checks with
ConsistOf + HaveField("GetName()", Equal
:=>
That didn't work. It turned out that the slice elements are values and their
GetName
method is only defined for pointers. Go can call it anyway, but Gomega can't (or doesn't). Perhaps it should also support that?Here's a reproducer:
The text was updated successfully, but these errors were encountered: