-
Notifications
You must be signed in to change notification settings - Fork 16
/
sender_test.go
45 lines (37 loc) · 1.28 KB
/
sender_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package xstats
import (
"errors"
"testing"
"time"
"github.com/stretchr/testify/assert"
)
func TestMultiSender(t *testing.T) {
fs1 := &fakeSender{}
fs2 := &fakeSendCloser{err: errors.New("foo")}
fs3 := &fakeSendCloser{err: errors.New("bar")}
m := MultiSender{fs1, fs2, fs3}
m.Count("foo", 1, "bar", "baz")
countCmd := cmd{"Count", "foo", 1, []string{"bar", "baz"}}
assert.Equal(t, countCmd, fs1.last)
assert.Equal(t, countCmd, fs2.last)
assert.Equal(t, countCmd, fs3.last)
m.Gauge("foo", 1, "bar", "baz")
gaugeCmd := cmd{"Gauge", "foo", 1, []string{"bar", "baz"}}
assert.Equal(t, gaugeCmd, fs1.last)
assert.Equal(t, gaugeCmd, fs2.last)
assert.Equal(t, gaugeCmd, fs3.last)
m.Histogram("foo", 1, "bar", "baz")
histoCmd := cmd{"Histogram", "foo", 1, []string{"bar", "baz"}}
assert.Equal(t, histoCmd, fs1.last)
assert.Equal(t, histoCmd, fs2.last)
assert.Equal(t, histoCmd, fs3.last)
m.Timing("foo", 1*time.Second, "bar", "baz")
timingCmd := cmd{"Timing", "foo", 1, []string{"bar", "baz"}}
assert.Equal(t, timingCmd, fs1.last)
assert.Equal(t, timingCmd, fs2.last)
assert.Equal(t, timingCmd, fs3.last)
assert.Equal(t, fs2.err, CloseSender(m))
assert.Equal(t, timingCmd, fs1.last)
assert.Equal(t, cmd{name: "Close"}, fs2.last)
assert.Equal(t, cmd{name: "Close"}, fs3.last)
}