title: Mock statsd client in Go test package
body: <p>I use <a href="https://github.com/cactus/go-statsd-client" rel="nofollow noreferrer">this</a> <code>statsd package</code> to send metrics to our <code>statsd server</code>. To initialize the client, I call a <code>metrics.Setup()</code> in my main which does the init. This package looks like this:</p>
  
  <p><strong>package:</strong></p>
  
  <pre><code>package metrics
  
  import (
      "fmt"
  
      "github.com/cactus/go-statsd-client/statsd"
  )
  
  // Client can be used to send stats to
  var Client StatsdAccess
  
  // Setup initialises metrics gathering
  func Setup() {
      if Client == nil {
          prefix := fmt.Sprintf("app.%s", logging.GetHost())
          std, err := statsd.NewBufferedClient(fmt.Sprintf("localhost:1234", prefix, 0, 0)
          if err != nil {
              logrus.Errorf("unable to dial the statsd host: %q", err)
              return
          }
          Client = std
      }
  }
  
  // StatsdAccess is used as interface to statsd functions
  type StatsdAccess interface {
      Inc(stat string, value int64, rate float32) error
      Gauge(stat string, value int64, rate float32) error
      Timing(stat string, delta int64, rate float32) error
  }
  </code></pre>
  
  <p>From this moment on, the other package send metrics though this global Client by doing this: <code>metrics.Client.Inc("some.counter", 1, 1.0)</code>. This works fine, but now I have a problem with my test files. They now fail when a package actually uses the <code>metrics package</code> to send metrics. This is obvious, because the metrics package has not been initialized, etc. So my question -I think- is: how can I mock the <code>statsd client</code> in my test files?</p>