Unexpected method call with custom struct constant.
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 35/100
- Issue type
- Bug
- Clarity
- Mostly clear
- Activity status
- Stale
- Tech stack
- go
- Domain
- testing-qa
Research direction
Start by reproducing the supplied MockedUserDao example against revision 4d4bfba8f1d1027c4fdbe371823030df51419987, comparing the configured providerID with the value in the failure. Then inspect testify/mock's argument-matching path and existing mock tests. Done means establishing whether the differing UUID values explain the failure or exposing a matching defect with a focused regression test.
Written by the indexing model from the issue text.
Description
I'm experiencing some strange behavior I think may be a bug. I have the following types.
package model
type IdentityProvider string
var IdentityProviderGoogle = "google"
var IdentityProviderOffice365 = "office365"
I then have the following mock interface and implementation
package dataaccess
//UserDao the service for working with Users
type UserDao interface {
//GetByProviderID get the user by the provider id
GetByProviderID(provider model.IdentityProvider, providerID string) (*model.User, error)
}
// MockedUserDao is a mocked object that implements an interface
// that describes an object that the code I am testing relies on.
type MockedUserDao struct {
dataaccess.UserDao
mock.Mock
}
//GetByProviderID get the the providerid
func (m *MockedUserDao) GetByProviderID(provider model.IdentityProvider, providerID string) (*model.User, error) {
args := m.Called(provider, providerID)
return nilSafeUser(args)
}
func nilSafeUser(args mock.Arguments) (*model.User, error) {
user := args.Get(0)
err := args.Error(1)
if user == nil {
return nil, err
}
return user.(*model.User), err
}
I then mock with the following call
userDao.On("GetByProviderID", model.IdentityProviderGoogle, "1c3a9049-2116-11e7-986e-acde48001122").Return(otherUserEmail, nil)
What I expect to happen:
My pointer to "otherUserEmail" to be returned
What actually happens. Mocking fails to return.
mock: Unexpected Method Call
-----------------------------
GetByProviderID(model.IdentityProvider,string)
0: "google"
1: "1c3a9040-2116-11e7-986e-acde48001122"
The closest call I have is:
GetByProviderID(model.IdentityProvider,string)
0: "google"
1: "1c3a9049-2116-11e7-986e-acde48001122"
I could be incorrect, but from my observation, the values appear to be the same memory in index 0, and the same string in index 1. I'm using revision 4d4bfba8f1d1027c4fdbe371823030df51419987 as my dependency via vendor directory.
Env: go version go1.7.4 darwin/amd64
- Dominant language
- Go
- Stars
- 26.2k
- Forks
- 1.9k
- Avg merge
- 2d 4h
- Merged PRs (30d)
- 2
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from stretchr/testify
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
-
bug
Difficulty 1/5 Under an hour Newbie friendliness 88/100
-
enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
-
internal/cleanup
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
All issues in stretchr/testify
Similar issues
-
optimization optimization:agents-md-curator
Difficulty 2/5 1-3 hours Newbie friendliness 86/100
githubnext/gh-aw-cao#13143 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
blinklabs-io/bursa#904 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
yanet-platform/ipfw-go#129 ·
-
bug confmap/provider/googlesecretmanagerprovider needs triage
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
open-telemetry/opentelemetry-collector-contrib#51273 · 2 comments ·
-
bug: AI Gateway client filter lists "Unknown" twice when NULL and literal Unknown clients coexist Openbug
Difficulty 2/5 1-3 hours Newbie friendliness 90/100