-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmetric_test.go
54 lines (43 loc) · 1.21 KB
/
metric_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
46
47
48
49
50
51
52
53
54
package stats
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestGauge(t *testing.T) {
name := "blabla"
tagExtractedName := "bla"
tags := []*Tag{{Name: "tag1", Value: "dummy"}}
g := NewGauge(name, tagExtractedName, tags)
assert.Equal(t, g.Name(), name)
assert.Equal(t, g.Tags(), tags)
assert.Equal(t, g.TagExtractedName(), tagExtractedName)
g.Set(1)
assert.Equal(t, g.Value(), uint64(1))
g.Inc()
assert.Equal(t, g.Value(), uint64(2))
g.Add(2)
assert.Equal(t, g.Value(), uint64(4))
g.Dec()
assert.Equal(t, g.Value(), uint64(3))
g.Sub(2)
assert.Equal(t, g.Value(), uint64(1))
}
func TestCounter(t *testing.T) {
name := "mong"
tagExtractedName := "mo"
c := NewCounter(name, tagExtractedName, nil)
assert.Equal(t, c.Name(), name)
assert.Equal(t, c.TagExtractedName(), tagExtractedName)
assert.Equal(t, c.Tags(), []*Tag(nil))
c.Inc()
c.Add(2)
assert.Equal(t, uint64(3), c.Latch())
assert.Equal(t, uint64(3), c.Value())
assert.Equal(t, uint64(3), c.IntervalValue())
assert.Equal(t, uint64(0), c.Latch())
assert.Equal(t, uint64(0), c.IntervalValue())
c.Add(2)
assert.Equal(t, uint64(2), c.Latch())
assert.Equal(t, uint64(5), c.Value())
assert.Equal(t, uint64(2), c.IntervalValue())
}