Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add OnOverwrite function #1205

Closed
wants to merge 7 commits into from
Closed

Conversation

sunhao1256
Copy link

@sunhao1256 sunhao1256 commented Jun 20, 2022

Summary

when mock repeate regist duplicate method name and arguments ,only return this first arguments , i want supply "OnOverwrite" function to overwrite the old regist which has been registed

Changes

mock.go add "Off" function

a := "xx"

d.Mock.On("hello", a).Return("xx1")
d.Mock.On("hello", a).Return("xx2")
get := d.Mock.MethodCalled("hello", a).Get(0) //return xx1
fmt.Println(get)

d.Mock.On("hello", a).Return("xx1")
d.Mock.Off("hello", a)
d.Mock.On("hello", a).Return("xx2")
get := d.Mock.MethodCalled("hello", a).Get(0) //return xx2
fmt.Println(get)

Motivation

we need off function

Related issues

#558
#166

@boyan-soubachov
Copy link
Collaborator

Is there a need for this if we implement the .Unset()/.Off() function mentioned in #558 ? I'd rather prioritise getting #558 implemented first.

@sunhao1256
Copy link
Author

Is there a need for this if we implement the .Unset()/.Off() function mentioned in #558 ? I'd rather prioritise getting #558 implemented first.

i modify OnOverwrite function to Off function , please review

@boyan-soubachov
Copy link
Collaborator

This isn't doing what #982 is doing though. We just need to agree/change the function naming in #982 and merge it.

@sunhao1256 sunhao1256 closed this Jun 23, 2022
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.

None yet

2 participants