-
Notifications
You must be signed in to change notification settings - Fork 6
/
main_test.go
47 lines (44 loc) · 1.34 KB
/
main_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
package main
import (
"bufio"
"bytes"
"math/rand"
"testing"
)
func TestWriteSeriesVMImport(t *testing.T) {
startTimestamp := int64(1234)
var bb bytes.Buffer
bw := bufio.NewWriter(&bb)
r := rand.New(rand.NewSource(startTimestamp))
sensorID := 789
rowsCount := 3
writeSeriesVMImport(bw, r, sensorID, rowsCount, startTimestamp)
if err := bw.Flush(); err != nil {
t.Fatalf("unexpected error in bw.Flush: %s", err)
}
result := bb.String()
resultExpected := `{"metric":{"__name__":"temperature","sensor_id":"789"},"values":[68.34,69.61,69.86],"timestamps":[1234,61234,121234]}` + "\n"
if result != resultExpected {
t.Fatalf("unexpected result;\ngot\n%s\nwant\n%s", result, resultExpected)
}
}
func TestWriteSeriesInflux(t *testing.T) {
startTimestamp := int64(1234)
var bb bytes.Buffer
bw := bufio.NewWriter(&bb)
r := rand.New(rand.NewSource(startTimestamp))
sensorID := 789
rowsCount := 3
writeSeriesInflux(bw, r, sensorID, rowsCount, startTimestamp)
if err := bw.Flush(); err != nil {
t.Fatalf("unexpected error in bw.Flush: %s", err)
}
result := bb.String()
resultExpected := `temperature,sensor_id=789 value=68.34 1234000000
temperature,sensor_id=789 value=69.61 61234000000
temperature,sensor_id=789 value=69.86 121234000000
`
if result != resultExpected {
t.Fatalf("unexpected result;\ngot\n%s\nwant\n%s", result, resultExpected)
}
}