-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathclient_test.go
76 lines (64 loc) · 1.73 KB
/
client_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
package rexgo
import "testing"
func TestDial(t *testing.T) {
addr := "localhost:8184"
rx, err := Dial(addr)
if err != nil {
t.Fatalf("Dial(%v) returned %v", addr, err)
}
rx.Close()
}
func TestSession(t *testing.T) {
addr := "localhost:8184"
rx, err := Dial(addr)
if err != nil {
t.Fatalf("client.Dial(%v) returned %v", addr, err)
}
s, err := rx.NewSession()
if err != nil {
t.Fatalf("client.NewSession() returned %v", err)
}
obj, err := s.Execute(`[name:var1]`, map[string]interface{}{"var1": "value1"})
if err != nil {
t.Fatalf("session.Script() returned %v", err)
}
if result, ok := obj[0].(map[string]interface{}); ok {
if result["name"] != "value1" {
t.Errorf(`script result: "name" expected to have "value1", got %v`, result["name"])
}
} else {
t.Errorf(`script result expected to be a map, got: %#v`, obj)
}
obj, err = s.Execute(`[name2:var1]`, nil)
if err != nil {
t.Fatalf("session.Script() returned %v", err)
}
if result, ok := obj[0].(map[string]interface{}); ok {
if result["name2"] != "value1" {
t.Errorf(`script result: "name2" expected to have "value1", got %v`, result["name"])
}
} else {
t.Errorf(`script result expected to be a map, got: %#v`, obj)
}
err = s.Close()
if err != nil {
t.Fatalf("session.Close() returned %v", err)
}
rx.Close()
}
func TestGraphOfGods(t *testing.T) {
rx, err := Dial("localhost:8184")
if err != nil {
t.Fatalf("%v", err)
}
rx.SetGraphName("graph")
bindings := map[string]interface{}{"godname": "saturn"}
obj, err := rx.Execute(`g.V('name',godname).in('father').in('father').name`, bindings)
if err != nil {
t.Fatalf("%v", err)
}
if obj[0] != "hercules" {
t.Errorf(`Saturn's grandchild expected to be Hercules, got: %#v`, obj)
}
rx.Close()
}