-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathinfluxdb_integration_test.go
68 lines (60 loc) · 1.38 KB
/
influxdb_integration_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
//go:build integration
// +build integration
package main
import (
"fmt"
"log"
"math/rand"
"net/url"
"strconv"
"testing"
"time"
influxdb "github.com/influxdata/influxdb/client"
"github.com/stretchr/testify/assert"
)
func Test_Write(t *testing.T) {
assert := assert.New(t)
host, err := url.Parse(fmt.Sprintf("http://%s:%d", "localhost", 8086))
assert.Nil(err)
ifConf := influxdb.Config{
URL: *host,
Username: "test",
Password: "password",
}
con, err := influxdb.NewClient(ifConf)
assert.Nil(err)
// Check connectivity
_, _, err = con.Ping()
assert.Nil(err)
var (
shapes = []string{"circle", "rectangle", "square", "triangle"}
colors = []string{"red", "blue", "green"}
sampleSize = 1000
pts = make([]influxdb.Point, sampleSize)
)
rand.Seed(42)
for i := 0; i < sampleSize; i++ {
pts[i] = influxdb.Point{
Measurement: "shapes",
Tags: map[string]string{
"color": strconv.Itoa(rand.Intn(len(colors))),
"shape": strconv.Itoa(rand.Intn(len(shapes))),
},
Fields: map[string]interface{}{
"value": rand.Intn(sampleSize),
},
Time: time.Now(),
Precision: "s",
Raw: "cpu,host=server01,region=uswest value=1 1434055562000000000",
}
}
bps := influxdb.BatchPoints{
Points: pts,
Database: "test",
RetentionPolicy: "default",
}
_, err = con.Write(bps)
if err != nil {
log.Fatal(err)
}
}