From c0f2e208c9967d3669551cd80dfd249ccf5593b7 Mon Sep 17 00:00:00 2001 From: Prudhvi Chaitanya Dhulipalla Date: Fri, 5 Jul 2019 14:14:25 -0700 Subject: [PATCH] Fixing specs after upgrading datadog --- Gopkg.lock | 5 ++--- Gopkg.toml | 2 +- scopedstatsd/client_test.go | 6 +++-- .../DataDog/datadog-go/statsd/statsd.go | 22 ++++++++++++++----- 4 files changed, 23 insertions(+), 12 deletions(-) diff --git a/Gopkg.lock b/Gopkg.lock index c4e811d0d..0ff626f26 100644 --- a/Gopkg.lock +++ b/Gopkg.lock @@ -2,12 +2,11 @@ [[projects]] - digest = "1:36975300f25d328c37e87d801e2e34038c53edcf15be8c2afb147f00de409386" + digest = "1:6c364e65eec127e77ec8b0696f1422890af3c19a252f2b72b98784ab24b9752e" name = "github.com/DataDog/datadog-go" packages = ["statsd"] pruneopts = "NUT" - revision = "8a13fa761f51039f900738876f2837198fba804f" - version = "2.2.0" + revision = "f6e76752dd64e7329d6b314f92a08748a78c2250" [[projects]] digest = "1:e30fbdce732588b475a444cbeabbcbef1c6c08b8d4f3efc142853551a1b0ab13" diff --git a/Gopkg.toml b/Gopkg.toml index 773fe4916..a954dd6bd 100644 --- a/Gopkg.toml +++ b/Gopkg.toml @@ -22,7 +22,7 @@ [[constraint]] name = "github.com/DataDog/datadog-go" - version = "2.2.0" + revision = "f6e76752dd64e7329d6b314f92a08748a78c2250" [[constraint]] name = "github.com/Shopify/sarama" diff --git a/scopedstatsd/client_test.go b/scopedstatsd/client_test.go index 44d3438d1..503465268 100644 --- a/scopedstatsd/client_test.go +++ b/scopedstatsd/client_test.go @@ -3,6 +3,8 @@ package scopedstatsd import ( "testing" + "github.com/pkg/errors" + "github.com/stretchr/testify/assert" ) @@ -10,7 +12,7 @@ func TestEnsure(t *testing.T) { var theNilOne Client = nil ensured := Ensure(theNilOne) assert.NotNil(t, ensured) - assert.NoError(t, ensured.Count("hi", 0, nil, 1.0)) + assert.Error(t, errors.New("statsd client is nil"), ensured.Count("hi", 0, nil, 1.0)) } func TestDoesSomething(t *testing.T) { @@ -49,7 +51,7 @@ func TestDoesSomething(t *testing.T) { }, } for _, fn := range testFuncs { - assert.NoError(t, fn()) + assert.Error(t, errors.New("statsd client is nil"), fn()) } }) } diff --git a/vendor/github.com/DataDog/datadog-go/statsd/statsd.go b/vendor/github.com/DataDog/datadog-go/statsd/statsd.go index 71a113cfc..2557f2d4a 100644 --- a/vendor/github.com/DataDog/datadog-go/statsd/statsd.go +++ b/vendor/github.com/DataDog/datadog-go/statsd/statsd.go @@ -67,6 +67,16 @@ const ( entityIDTagName = "dd.internal.entity_id" ) +type noClientErr string + +// ErrNoClient is returned if statsd reporting methods are invoked on +// a nil client. +const ErrNoClient = noClientErr("statsd client is nil") + +func (e noClientErr) Error() string { + return string(e) +} + /* Stat suffixes */ @@ -220,7 +230,7 @@ func (c *Client) format(name string, value interface{}, suffix []byte, tags []st // SetWriteTimeout allows the user to set a custom UDS write timeout. Not supported for UDP. func (c *Client) SetWriteTimeout(d time.Duration) error { if c == nil { - return fmt.Errorf("Client is nil") + return ErrNoClient } return c.writer.SetWriteTimeout(d) } @@ -307,7 +317,7 @@ func copyAndResetBuffer(buf *bytes.Buffer) []byte { // Flush forces a flush of the pending commands in the buffer func (c *Client) Flush() error { if c == nil { - return fmt.Errorf("Client is nil") + return ErrNoClient } c.Lock() defer c.Unlock() @@ -361,7 +371,7 @@ func (c *Client) sendMsg(msg []byte) error { // send handles sampling and sends the message over UDP. It also adds global namespace prefixes and tags. func (c *Client) send(name string, value interface{}, suffix []byte, tags []string, rate float64) error { if c == nil { - return fmt.Errorf("Client is nil") + return ErrNoClient } if rate < 1 && rand.Float64() > rate { return nil @@ -419,7 +429,7 @@ func (c *Client) TimeInMilliseconds(name string, value float64, tags []string, r // Event sends the provided Event. func (c *Client) Event(e *Event) error { if c == nil { - return fmt.Errorf("Client is nil") + return ErrNoClient } stat, err := e.Encode(c.Tags...) if err != nil { @@ -437,7 +447,7 @@ func (c *Client) SimpleEvent(title, text string) error { // ServiceCheck sends the provided ServiceCheck. func (c *Client) ServiceCheck(sc *ServiceCheck) error { if c == nil { - return fmt.Errorf("Client is nil") + return ErrNoClient } stat, err := sc.Encode(c.Tags...) if err != nil { @@ -455,7 +465,7 @@ func (c *Client) SimpleServiceCheck(name string, status ServiceCheckStatus) erro // Close the client connection. func (c *Client) Close() error { if c == nil { - return fmt.Errorf("Client is nil") + return ErrNoClient } select { case c.stop <- struct{}{}: