Skip to content

mock: Call.Unset panics #1236

Description

@hieunguyen1809

Hi team, I'm using testify to testing my method but encounter this issue (It only occur if using matchedBy arg)
When I using mock following by example but got error when using mockCall.Unset().
playground: https://go.dev/play/p/oQ2sGSRCtbR

Activity

  1. changed the title [-][ISSUE] mockCall.Unset failed[/-] [+][ISSUE] mockCall.Unset cause panic[/+] on Jul 22, 2022
  2. added a commit that references this issue on Jul 27, 2022
  3. lisitsky commented on Aug 15, 2022

    @lisitsky
    Contributor

    I've got the same trouble :(
    Could you check and may be vote for my fix for this?
    #1250

  4. at-syot commented on Nov 17, 2022

    @at-syot

    For people who face this issue, i use this code

    	unset := func(call *mock.Call) {
    		if call != nil {
    			call.Parent.ExpectedCalls = []*mock.Call{}
    		}
    	}
    	var caller *mock.Call
    	unset(caller)
    

    as temporary fix. you can try this to

  5. gordonlee commented on Dec 5, 2022

    @gordonlee

    Just fyi, I put short snippet which only specific method would be deleted based on @at-syot 's code

    var unsetFn = func(call *mock.Call) {
    	if call != nil {
    		var newList []*mock.Call
    		for _, c := range call.Parent.ExpectedCalls {
    			if c.Method != call.Method {
    				newList = append(newList, c)
    			}
    		}
    		call.Parent.ExpectedCalls = newList
    	}
    }
    
    // caller side
    unsetFn(mockInstance.On("SOME_METHOD_YOU_WANT_TO_UNSET"))
  6. lisitsky commented on Dec 5, 2022

    @lisitsky
    Contributor

    Hello @gordonlee .
    I have a fix #1250 but have no permission merge it.
    Could you help promote it?

  7. hugoboos commented on Dec 14, 2022

    @hugoboos

    Running in the same problem. A fix would be appreciated 😄

  8. changed the title [-][ISSUE] mockCall.Unset cause panic[/-] [+]mockCall.Unset cause panic[/+] on Mar 7, 2024
  9. changed the title [-]mockCall.Unset cause panic[/-] [+]mock: Call.Unset panics[/+] on May 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions