title: How to Mock only specific method in Golang
body: <p>I am fairly new to golang and I am struggling with a simple task.</p>
  
  <p>I have the following class in golang</p>
  
  <pre><code>type struct A {
  }
  
  func (s *A) GetFirst() {
      s.getSecond()
  }
  
  func (s *A) getSecond() {
      // do something
  }
  </code></pre>
  
  <p>And I want to write some tests for it however for that I need to override <code>getSecond()</code>. I attempted to do the following in my test files</p>
  
  <pre><code>type Ai interface {
      getSecond()
  }
  
  type testA struct {
      A
  }
  
  func (s *testA) getSecond() {
       // do nothing
  }
  
  func TestA(t *testing.T) {
     a := &amp;A{}
     t := &amp;testA{A: a}
     t.GetFirst()  
  }
  </code></pre>
  
  <p>The idea here is to expose A <code>getSecond()</code> method to an interface and override by using embedding however this does not seem to work. The test still calls the original implementation of <code>getSecond()</code> instead of my mocked one.</p>
  
  <p>One solution would of course be to create a proper interface for A which  contains <code>getFirst()</code> and <code>getSecond()</code> and then in the test create a struct implementing both where <code>getFirst()</code> call the original implementation and <code>getSecond()</code> a dummy however I feel this is cumbersome and not the correct way of doing things.</p>
  
  <p>Another possibility would be to assign <code>getSecond()</code> in the real implementation to a variable and override the variable in test but I also feel it is a bit strange to do this just for a simple override.</p>
  
  <p>Am I going all wrong about this? Is there any way simpler way to do this using golang?</p>