-
Notifications
You must be signed in to change notification settings - Fork 1
/
influxdb_test.go
68 lines (62 loc) · 1.76 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
package main
import (
"container/list"
"fmt"
"testing"
)
func testSetup() {
dblog = list.New()
}
func TestAppendToLog(t *testing.T) {
testSetup()
dbloglen := dblog.Len()
if dbloglen != 0 {
t.Error("Len should be 0, was", dbloglen)
}
appendToLog("SHOW MEASUREMENTS")
dbloglen = dblog.Len()
if dbloglen != 1 {
t.Error("Len should not be 1, was", dbloglen)
}
}
func TestAppendToLogTakesOnly10Elements(t *testing.T) {
testSetup()
for i := 1; i < 12; i++ {
appendToLog(fmt.Sprintf("SELECT * FROM data LIMIT %d", i))
}
dbloglen := dblog.Len()
if dbloglen != 10 {
t.Error("Len should not be 10, was", dbloglen)
}
expected_first := "SELECT * FROM data LIMIT 2"
observed_first := dblog.Front().Value
if expected_first != observed_first {
t.Error(fmt.Sprintf("First element should be %s, was %s", expected_first, observed_first))
}
expected_last := "SELECT * FROM data LIMIT 11"
observed_last := dblog.Back().Value
if expected_last != observed_last {
t.Error(fmt.Sprintf("First element should be %s, was %s", expected_last, observed_last))
}
}
func TestGetLogOptions(t *testing.T) {
testSetup()
appendToLog("SELECT * FROM data LIMIT 1;")
expected := "<option value='SELECT * FROM data LIMIT 1;'>SELECT * FROM data LIMIT 1;</option>"
observed := getLogOptions()
if expected != observed {
t.Error(fmt.Sprintf("Observed %s was not expected: %s", observed, expected))
}
}
func TestIfExists(t *testing.T) {
connections := list.New()
connections.PushBack("http://localhost:8086")
observed := getExists(connections, "http://localhost:8086")
if !observed {
t.Error(fmt.Sprintf("Should be true, was %v", observed))
}
observed = getExists(connections, "http://otherhost.com:8086")
if observed {
t.Error(fmt.Sprintf("Should be false, was %v", observed))
}
}