Unexpected method call with custom struct constant.

Open
#429 5 comments 0 reactions 0 assignees View on GitHub

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

input needed

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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from stretchr/testify

All issues in stretchr/testify

Similar issues

More Go issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.