Skip to content

Commit

Permalink
Add noop client and tests
Browse files Browse the repository at this point in the history
Resolves DataDog#88
  • Loading branch information
Sam Park committed Sep 10, 2019
1 parent 5f2042b commit 584a084
Show file tree
Hide file tree
Showing 2 changed files with 122 additions and 0 deletions.
59 changes: 59 additions & 0 deletions statsd/noop.go
Original file line number Diff line number Diff line change
@@ -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
}
63 changes: 63 additions & 0 deletions statsd/noop_test.go
Original file line number Diff line number Diff line change
@@ -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")
}
}

0 comments on commit 584a084

Please sign in to comment.