Golang test mock functions best practices
<p>I am developing some tests for my code (using the <em>testing</em> package), and I am wondering what's the best way to mock functions inside the tested function:</p>

<p>Should I pass the function as parameter?
In that case, what if that function calls another function? Should I pass both the first and second function as parameters in the tested one?</p>

<p>Note: some of the functions are called on objects (i.e. someObj.Create()) and use HTTP API calls.</p>

<p>UPDATE for clarification:</p>

<p>Example: functions</p>

<pre><code>func f1() error {
  ... //some API call
}

func (s *SomeStruct) f2() error {
  return f1
}

func f3() error {
  return nil
}

func f4() error {
  ...
  err = obj.f2()
  ...
  err = f3()
  ...
}
</code></pre>

<p>For the above: if I want to test f4, what's the best way to mock f2 and f3?</p>

<p>If I pass f2 and f3 to f4 as parameters it would work, but then what for the f2 test? Should I pass f1 to f2 as parameter?</p>

<p>And if that's it, should then f4 have f1 as well in the parameters?</p>