Skip to content

add OnOverwrite function#1205

Closed
ghost wants to merge 7 commits intomasterfrom
unknown repository
Closed

add OnOverwrite function#1205
ghost wants to merge 7 commits intomasterfrom
unknown repository

Conversation

@ghost
Copy link
Copy Markdown

@ghost ghost 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
Copy Markdown
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.

@ghost
Copy link
Copy Markdown
Author

ghost commented Jun 21, 2022

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
Copy Markdown
Collaborator

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

@ghost ghost closed this Jun 23, 2022
This pull request was closed.
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.

1 participant