-
Notifications
You must be signed in to change notification settings - Fork 1
/
metric_test.go
72 lines (63 loc) · 1.33 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package graphite
import (
"fmt"
"testing"
"time"
)
func TestNewMetric(t *testing.T) {
timestamp := time.Now().Unix()
metric := NewMetric("test1", 12, timestamp)
if metric.Timestamp != timestamp {
t.Fail()
}
if tmp, ok := metric.Value.(int); !ok {
t.Fail()
} else {
if tmp != 12 {
t.Fail()
}
}
if metric.Name != "test1" {
t.Fail()
}
}
func TestMetric_ToString(t *testing.T) {
timestamp := time.Now().Unix()
metric := NewMetric("test1", 12, timestamp)
if metric.ToString() != fmt.Sprintf("test1 12 %d", timestamp) {
t.Fail()
}
}
func TestMetric_ToByte(t *testing.T) {
timestamp := time.Now().Unix()
metric := NewMetric("test1", 12, timestamp)
if string(metric.ToByte()) != fmt.Sprintf("test1 12 %d\n", timestamp) {
t.Fail()
}
}
func BenchmarkNewMetric(b *testing.B) {
b.StopTimer()
timestamp := time.Now().Unix()
b.StartTimer()
for i := 0; i < b.N; i++ {
_ = NewMetric("test1", 12, timestamp)
}
}
func BenchmarkMetric_ToString(b *testing.B) {
b.StopTimer()
timestamp := time.Now().Unix()
metric := NewMetric("test1", 12, timestamp)
b.StartTimer()
for i := 0; i < b.N; i++ {
_ = metric.ToString()
}
}
func BenchmarkMetric_ToByte(b *testing.B) {
b.StopTimer()
timestamp := time.Now().Unix()
metric := NewMetric("test1", 12, timestamp)
b.StartTimer()
for i := 0; i < b.N; i++ {
_ = metric.ToByte()
}
}