-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy paththingsdb_test.go
More file actions
56 lines (45 loc) · 1.09 KB
/
thingsdb_test.go
File metadata and controls
56 lines (45 loc) · 1.09 KB
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
package thingsdb
import (
"crypto/tls"
"os"
"testing"
)
// TestNewConn
func TestNewConn(t *testing.T) {
conn := NewConn("loclhost", 9000, nil)
if conn == nil {
t.Fatalf("Failed to create a new connection")
}
}
// TestPlayground
func TestPlayground(t *testing.T) {
want := "Welcome at ThingsDB!"
// Only required for a secure connection
conf := &tls.Config{
InsecureSkipVerify: false,
}
// Create a new ThingsDB connection
conn := NewConn("playground.thingsdb.net", 9400, conf)
if err := conn.Connect(); err != nil {
t.Fatalf(`Failed to connect: %v`, err)
} else {
// Close the connection at the end of this function
defer conn.Close()
token := os.Getenv("TI_TOKEN")
if err := conn.AuthToken(token); err != nil {
t.Fatalf(`Failed to authenticate: %v`, err)
} else {
vars := map[string]interface{}{
"index": 1,
}
data, err := conn.Query(
"//Doc", // Scope
".greetings[index];", // ThingsDB code
vars, // Variable
)
if data != want || err != nil {
t.Fatalf(`%q != %q, error: %v`, data, want, err)
}
}
}
}