-
Notifications
You must be signed in to change notification settings - Fork 0
/
metrics_test.go
100 lines (79 loc) · 2.03 KB
/
metrics_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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
package graphite
import (
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
var _ = Describe("graphite metrics", func() {
Context("metric sum", func() {
var (
metric MetricSum
)
BeforeEach(func() {
metric = MetricSum{}
})
It("should initialise with value zero", func() {
Expect(metric.Calculate()).To(Equal("0"))
})
It("should update the internal value with the amount received", func() {
metric.Update(5)
Expect(metric.Calculate()).To(Equal("5"))
metric.Update(3)
Expect(metric.Calculate()).To(Equal("8"))
})
It("should clear the internal value", func() {
metric.Update(5)
metric.Clear()
Expect(metric.Calculate()).To(Equal("0"))
})
})
Context("metric average", func() {
var (
metric MetricAverage
)
BeforeEach(func() {
metric = MetricAverage{}
})
It("should initialise with value zero", func() {
Expect(metric.Calculate()).To(Equal("0"))
})
It("should update the internal value with the amount received", func() {
metric.Update(2)
Expect(metric.Calculate()).To(Equal("2.000000"))
metric.Update(4)
Expect(metric.Calculate()).To(Equal("3.000000"))
})
It("should use up to 6 decimals", func() {
metric.Update(1)
metric.Update(3)
metric.Update(6)
Expect(metric.Calculate()).To(Equal("3.333333"))
})
It("should clear the internal value", func() {
metric.Update(5)
metric.Clear()
Expect(metric.Calculate()).To(Equal("0"))
})
})
Context("metric active/inactive", func() {
var (
metric MetricActive
)
BeforeEach(func() {
metric = MetricActive{}
})
It("should initialise with value inactive", func() {
Expect(metric.Calculate()).To(Equal("0"))
})
It("should update the internal value with the status received", func() {
metric.Update(true)
Expect(metric.Calculate()).To(Equal("1"))
metric.Update(false)
Expect(metric.Calculate()).To(Equal("0"))
})
It("should clear the internal value", func() {
metric.Update(true)
metric.Clear()
Expect(metric.Calculate()).To(Equal("0"))
})
})
})