From 098128fd102520c289cc5aef04afa388f10998a9 Mon Sep 17 00:00:00 2001 From: techfg Date: Tue, 18 Mar 2025 12:48:09 -0700 Subject: [PATCH 1/2] chore: update docs for Unset #1621 --- mock/mock.go | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/mock/mock.go b/mock/mock.go index eb5682df9..6f734feef 100644 --- a/mock/mock.go +++ b/mock/mock.go @@ -208,9 +208,16 @@ func (c *Call) On(methodName string, arguments ...interface{}) *Call { return c.Parent.On(methodName, arguments...) } -// Unset removes a mock handler from being called. +// Unset removes all mock handlers that satisfy the call instance arguments from being +// called. Only supported on call instances with static input arguments. // -// test.On("func", mock.Anything).Unset() +// For example, the only handler remaining after the following would be `2, 2`: +// +// test. +// On("func", 2, 2).Return(0). +// On("func", 3, 3).Return(0). +// On("func", Anything, Anything).Return(0) +// test.On("func", 3, 3).Unset() func (c *Call) Unset() *Call { var unlockOnce sync.Once From c6ac9bb91dd4966b95a61971926b69a5d8ac1506 Mon Sep 17 00:00:00 2001 From: techfg Date: Fri, 21 Mar 2025 06:25:01 -0700 Subject: [PATCH 2/2] chore: update per PR feedback --- mock/mock.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/mock/mock.go b/mock/mock.go index 6f734feef..da9f57365 100644 --- a/mock/mock.go +++ b/mock/mock.go @@ -211,13 +211,13 @@ func (c *Call) On(methodName string, arguments ...interface{}) *Call { // Unset removes all mock handlers that satisfy the call instance arguments from being // called. Only supported on call instances with static input arguments. // -// For example, the only handler remaining after the following would be `2, 2`: +// For example, the only handler remaining after the following would be "MyMethod(2, 2)": // -// test. -// On("func", 2, 2).Return(0). -// On("func", 3, 3).Return(0). -// On("func", Anything, Anything).Return(0) -// test.On("func", 3, 3).Unset() +// Mock. +// On("MyMethod", 2, 2).Return(0). +// On("MyMethod", 3, 3).Return(0). +// On("MyMethod", Anything, Anything).Return(0) +// Mock.On("MyMethod", 3, 3).Unset() func (c *Call) Unset() *Call { var unlockOnce sync.Once