title: fulfilling nested interfaces in golang
body: <p>I have an Interface that has a lot of submethods.</p>
  
  <pre><code>type InterfaceCheckout interface {
      GetID()    int
      GetItems() []InterfaceCartItem
      // ... then like 30more methods
  }
  </code></pre>
  
  <p>I have a method that only makes use of the GetItems method.</p>
  
  <pre><code>func GetRates(checkoutI InterfaceCheckout) []Rate {
      for _, item := range checkoutI.GetItesm() {
          p := item.GetProduct()
      }
  }
  </code></pre>
  
  <p>I'd like to be able to test this <code>GetRates</code> method without mocking all of the methods in <code>InterfaceCheckout</code>.</p>
  
  <p>I thought I'd be able to:</p>
  
  <ol>
  <li>create some smaller interfaces that specify only the methods I'm making use of</li>
  <li>cast the input as this new interface</li>
  <li><p>pass through to a new internal method </p>
  
  <pre><code>func GetRates(checkoutI InterfaceCheckout) []Rate {
      getRates(checkoutWrapper(checkoutI))
  }
  
  func getRates(checkoutI checkoutWrapper) []Rate {
      for _, item := range checkoutI.GetItesm() {
          p := item.GetProduct()
      }
  }
  
  // smaller wrapper interfaces
  type checkoutWrapper interface {
      GetItems() []InterfaceCartItem
  }
  </code></pre></li>
  </ol>
  
  <p>The problem I hit is that the <code>InterfaceCartItem</code> that is returned by <code>GetItems</code> has about 30 methods listed off in the interface, and I'm only using one of them <code>GetProduct</code>. So I thought I could use the same solution and create an interface with the one method I need, but when I try to change the type that is returned from <code>checkoutWrapper@GetItems()</code> golang says that <code>checkoutI</code> no longer satisfies the <code>checkoutWrapper</code> interface because it returns a different type from <code>GetItems</code> which is technically true...</p>
  
  <p>Code that I tried that doesn't work</p>
  
  <pre><code>func GetRates(checkoutI InterfaceCheckout) []Rate {
      getRates(checkoutWrapper(checkoutI))
  }
  
  func getRates(checkoutI InterfaceCheckout) []Rate {
      for _, item := range checkoutI.GetItesm() {
          p := item.GetProduct()
      }
  }
  
  // smaller wrapper interfaces
  type checkoutWrapper interface {
      GetItems() []itemWrapper
  }
  
  type itemWrapper interface {
      GetProduct() InterfaceProduct
  }
  </code></pre>
  
  <p>so is interface method validation only done one level deep?</p>