diff --git a/statsd/noop.go b/statsd/noop.go new file mode 100644 index 000000000..eb8166906 --- /dev/null +++ b/statsd/noop.go @@ -0,0 +1,59 @@ +package statsd + +import "time" + +// NoOpClient is a statsd client that does nothing. Can be useful in testing +// situations for library users. +type NoOpClient struct{} + +func (n *NoOpClient) Gauge(name string, value float64, tags []string, rate float64) error { + return nil +} + +func (n *NoOpClient) Count(name string, value int64, tags []string, rate float64) error { + return nil +} + +func (n *NoOpClient) Histogram(name string, value float64, tags []string, rate float64) error { + return nil +} + +func (n *NoOpClient) Distribution(name string, value float64, tags []string, rate float64) error { + return nil +} + +func (n *NoOpClient) Decr(name string, tags []string, rate float64) error { + return nil +} + +func (n *NoOpClient) Incr(name string, tags []string, rate float64) error { + return nil +} + +func (n *NoOpClient) Set(name string, value string, tags []string, rate float64) error { + return nil +} + +func (n *NoOpClient) Timing(name string, value time.Duration, tags []string, rate float64) error { + return nil +} + +func (n *NoOpClient) TimeInMilliseconds(name string, value float64, tags []string, rate float64) error { + return nil +} + +func (n *NoOpClient) Event(e *Event) error { + return nil +} + +func (n *NoOpClient) SimpleEvent(title, text string) error { + return nil +} + +func (n *NoOpClient) ServiceCheck(sc *ServiceCheck) error { + return nil +} + +func (n *NoOpClient) SimpleServiceCheck(name string, status ServiceCheckStatus) error { + return nil +} diff --git a/statsd/noop_test.go b/statsd/noop_test.go new file mode 100644 index 000000000..7575003de --- /dev/null +++ b/statsd/noop_test.go @@ -0,0 +1,63 @@ +package statsd + +import ( + "testing" + "time" +) + +func TestNoOpClient(t *testing.T) { + c := NoOpClient{} + tags := []string{"a:b"} + + if c.Gauge("asd", 123.4, tags, 56.0) != nil { + t.Error("Gauge output not nil") + } + + if c.Count("asd", 1234, tags, 56.0) != nil { + t.Error("Count output not nil") + } + + if c.Histogram("asd", 12.34, tags, 56.0) != nil { + t.Error("Histogram output not nil") + } + + if c.Distribution("asd", 1.234, tags, 56.0) != nil { + t.Error("Distribution output not nil") + } + + if c.Decr("asd", tags, 56.0) != nil { + t.Error("Decr output not nil") + } + + if c.Incr("asd", tags, 56.0) != nil { + t.Error("Incr output not nil") + } + + if c.Set("asd", "asd", tags, 56.0) != nil { + t.Error("Set output not nil") + } + + if c.Timing("asd", time.Second, tags, 56.0) != nil { + t.Error("Timing output not nil") + } + + if c.TimeInMilliseconds("asd", 1234.5, tags, 56.0) != nil { + t.Error("TimeInMilliseconds output not nil") + } + + if c.Event(nil) != nil { + t.Error("Event output not nil") + } + + if c.SimpleEvent("asd", "zxc") != nil { + t.Error("SimpleEvent output not nil") + } + + if c.ServiceCheck(nil) != nil { + t.Error("ServiceCheck output not nil") + } + + if c.SimpleServiceCheck("asd", Ok) != nil { + t.Error("SimpleServiceCheck output not nil") + } +}