forked from influxdata/influxdb-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinfluxdb_test.go
93 lines (74 loc) · 1.61 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
91
92
93
package influxdb
import (
"testing"
)
func TestClient(t *testing.T) {
client, err := NewClient(&ClientConfig{})
if err != nil {
t.Error(err)
}
if err := client.CreateClusterAdmin("admin", "password"); err != nil {
t.Error(err)
}
admins, err := client.GetClusterAdminList()
if err != nil {
t.Error(err)
}
if len(admins) != 2 {
t.Error("more than two admins returned")
}
if err := client.CreateDatabase("foobar"); err != nil {
t.Error(err)
}
dbs, err := client.GetDatabaseList()
if err != nil {
t.Error(err)
}
if len(dbs) != 1 && dbs[0]["foobar"] == nil {
t.Errorf("List of databases don't match")
}
if err := client.CreateDatabaseUser("foobar", "dbuser", "pass"); err != nil {
t.Error(err)
}
if err := client.AlterDatabasePrivilege("foobar", "dbuser", true); err != nil {
t.Error(err)
}
users, err := client.GetDatabaseUserList("foobar")
if err != nil {
t.Error(err)
}
if len(users) != 1 {
t.Error("more than one user returned")
}
client, err = NewClient(&ClientConfig{
Username: "dbuser",
Password: "pass",
Database: "foobar",
})
if err != nil {
t.Error(err)
}
series := &Series{
Name: "ts9",
Columns: []string{"value"},
Points: [][]interface{}{
[]interface{}{1.0},
},
}
if err := client.WriteSeries([]*Series{series}); err != nil {
t.Error(err)
}
result, err := client.Query("select * from ts9")
if err != nil {
t.Error(err)
}
if len(result) != 1 {
t.Error("more than one time series returned")
}
if len(result[0].Points) != 1 {
t.Error("Larger time series returned")
}
if result[0].Points[0][2].(float64) != 1 {
t.Fail()
}
}