forked from evcc-io/evcc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinfluxdb_test.go
90 lines (78 loc) · 1.89 KB
/
influxdb_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
package server
import (
"testing"
"github.com/benbjohnson/clock"
"github.com/evcc-io/evcc/util"
inf2 "github.com/influxdata/influxdb-client-go/v2"
"github.com/influxdata/influxdb-client-go/v2/api/write"
"github.com/stretchr/testify/assert"
)
type influxWriter struct {
t *testing.T
p []*write.Point
idx int
}
func (w *influxWriter) WritePoint(p *write.Point) {
if w.idx >= len(w.p) {
w.t.Fatal("too many points")
}
assert.Equal(w.t, w.p[w.idx], p)
w.idx++
}
func (w *influxWriter) finish() {
assert.Len(w.t, w.p, w.idx, "not enough points")
}
func TestInfluxTypes(t *testing.T) {
m := &Influx{
log: util.NewLogger("foo"),
clock: clock.NewMock(),
}
{
// string value
w := &influxWriter{
t: t, p: []*write.Point{inf2.NewPoint("foo", nil, map[string]any{"value": 1}, m.clock.Now())},
}
m.writeComplexPoint(w, util.Param{Key: "foo", Val: 1}, nil)
w.finish()
}
{
// nil value - https://github.com/evcc-io/evcc/issues/5950
w := &influxWriter{
t: t, p: []*write.Point{inf2.NewPoint("phasesConfigured", nil, map[string]any{"value": nil}, m.clock.Now())},
}
m.writeComplexPoint(w, util.Param{Key: "phasesConfigured", Val: nil}, nil)
w.finish()
}
{
// phases array
w := &influxWriter{
t: t, p: []*write.Point{inf2.NewPoint("foo", nil, map[string]any{
"l1": 1.0,
"l2": 2.0,
"l3": 3.0,
}, m.clock.Now())},
}
m.writeComplexPoint(w, util.Param{Key: "foo", Val: [3]float64{1, 2, 3}}, nil)
w.finish()
}
{
// phases slice
w := &influxWriter{
t: t, p: []*write.Point{inf2.NewPoint("foo", nil, map[string]any{
"l1": 1.0,
"l2": 2.0,
"l3": 3.0,
}, m.clock.Now())},
}
m.writeComplexPoint(w, util.Param{Key: "foo", Val: []float64{1, 2, 3}}, nil)
w.finish()
}
{
// arbitrary slice
w := &influxWriter{
t: t, p: nil,
}
m.writeComplexPoint(w, util.Param{Key: "foo", Val: []float64{1, 2, 3, 4}}, nil)
w.finish()
}
}