forked from influxdata/kapacitor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpoint_test.go
82 lines (77 loc) · 1.91 KB
/
point_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
package influxdb_test
import (
"testing"
"time"
"github.com/influxdata/kapacitor/influxdb"
)
func TestPoint_Bytes(t *testing.T) {
fields := map[string]interface{}{"value": float64(1), "another": int64(42)}
tags := map[string]string{"host": "serverA", "dc": "nyc"}
tm, _ := time.Parse(time.RFC3339Nano, "2000-01-01T12:34:56.789012345Z")
tests := []struct {
name string
precision string
exp string
t time.Time
}{
{
name: "zero time",
precision: "",
exp: "cpu,dc=nyc,host=serverA another=42i,value=1",
},
{
name: "no precision",
precision: "",
exp: "cpu,dc=nyc,host=serverA another=42i,value=1 946730096789012345",
t: tm,
},
{
name: "nanosecond precision",
precision: "ns",
exp: "cpu,dc=nyc,host=serverA another=42i,value=1 946730096789012345",
t: tm,
},
{
name: "microsecond precision",
precision: "u",
exp: "cpu,dc=nyc,host=serverA another=42i,value=1 946730096789012",
t: tm,
},
{
name: "millisecond precision",
precision: "ms",
exp: "cpu,dc=nyc,host=serverA another=42i,value=1 946730096789",
t: tm,
},
{
name: "second precision",
precision: "s",
exp: "cpu,dc=nyc,host=serverA another=42i,value=1 946730096",
t: tm,
},
{
name: "minute precision",
precision: "m",
exp: "cpu,dc=nyc,host=serverA another=42i,value=1 15778834",
t: tm,
},
{
name: "hour precision",
precision: "h",
exp: "cpu,dc=nyc,host=serverA another=42i,value=1 262980",
t: tm,
},
}
for _, test := range tests {
p := influxdb.Point{
Name: "cpu",
Tags: tags,
Fields: fields,
Time: test.t,
}
if got, exp := string(p.Bytes(test.precision)), test.exp; got != exp {
t.Errorf("%s: Bytes() mismatch:\n actual: %v\n exp: %v",
test.name, got, exp)
}
}
}