title: Testing a method that accepts callback function that doesn't return a value in Golang
body: <p>I'm trying to test the following function: </p>
  
  <pre><code>// SendRequestAsync sends request asynchronously, accepts callback
  //  func, which it invokes
  //
  // Parameters:
  // - `context` : some context
  // - `token` : some token
  // - `apiURL` : the URL to hit
  // - `callType` : the type of request to make. This should be one of
  //  the HTTP verbs (`"GET"`, `"POST"`, `"PUT"`, `"DELETE"`, ...)
  // - `callBack` : the func to invoke upon completion
  // - `callBackCustomData`: the data to invoke `callBack` with
  //
  // Since this is an async request, it doesn't return anything.
  func (a *APICoreSt) SendRequestAsync(context interface{}, token string, apiURL string, callType APIType, header map[string]string, jsonBody []byte,
      callBack OnCompletion, callBackCustomData interface{}) {
      go func(data interface{}) {
          callBack(a.SendRequest(context, token, apiURL, callType, header, jsonBody), data)
      }(callBackCustomData)
  }
  </code></pre>
  
  <p>where <code>OnCompletion</code> is defined by: </p>
  
  <pre><code>type OnCompletion func(result CallResultSt, data interface{})
  </code></pre>
  
  <p>My mind instantly thinks to create a spy callback. To do so, I forked <a href="https://godoc.org/github.com/nyarly/spies" rel="nofollow noreferrer">this framework</a>, came up with the following: </p>
  
  <pre><code>// outside the test function
  type MySpy struct {
      *spies.Spy
  }
  
  func (my *MySpy) Callback(res CallResultSt, data interface{}) {
      my.Called(res, data)
      fmt.Println("Hello world")
      return
  }
  
  //in the test function
  spy := new(MySpy)
  
  //...some table-driven test logic the generator came up with, containing my data
  
  spy.MatchMethod("Callback", spies.AnyArgs)
  assert.NotEmpty(t, spies.CallsTo("Callback"))
  </code></pre>
  
  <p>and it greeted me with </p>
  
  <pre><code>panic: runtime error: invalid memory address or nil pointer dereference [recovered]
      panic: runtime error: invalid memory address or nil pointer dereference
  </code></pre>
  
  <p>How do I remedy this, and test this method?</p>