-
Notifications
You must be signed in to change notification settings - Fork 59
/
connect_test.go
124 lines (98 loc) · 2.06 KB
/
connect_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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
package conduit
import (
_ "github.com/codegangsta/envy/autoload"
"os"
"testing"
)
var testHost string
var testUser string
var testCert string
func init() {
testHost = os.Getenv("GOCONDUIT_HOST")
testUser = os.Getenv("GOCONDUIT_USER")
testCert = os.Getenv("GOCONDUIT_CERT")
}
type conduitCapabilitiesResponse struct {
Authentication []string `json:"authentication"`
Signatures []string `json:"signatures"`
Input []string `json:"input"`
Output []string `json:"output"`
}
func TestCall(t *testing.T) {
conn, err := Dial(testHost)
if err != nil {
t.Fatal(err)
}
err = conn.Connect(testUser, testCert)
if err != nil {
t.Fatal(err)
}
type params struct {
Names []string `json:"names"`
Session *Session `json:"__conduit__"`
}
type result map[string]*struct {
URI string `json:"uri"`
FullName string `json:"fullName"`
Status string `json:"status"`
}
p := ¶ms{
Names: []string{"T1"},
Session: conn.Session,
}
var r result
err = conn.Call("phid.lookup", p, &r)
if err != nil {
t.Fatal(err)
}
t.Logf("%+v\n", r)
}
func TestCapabilities(t *testing.T) {
var resp conduitCapabilitiesResponse
err := call(testHost+"/api/conduit.getcapabilities", nil, &resp)
if err != nil {
t.Fatal(err)
}
t.Logf("%+v\n", resp)
}
func TestConnect(t *testing.T) {
conn, err := Dial(testHost)
if err != nil {
t.Fatal(err)
}
if conn == nil {
t.Fatal("nil connection")
}
err = conn.Connect(testUser, testCert)
if err != nil {
t.Fatal(err)
}
if conn.host != "https://code.interworks.com" {
t.Error("bad host")
}
if conn.Session == nil {
t.Error("missing conduit session")
}
if conn.Session.SessionKey == "" {
t.Error("missing session key")
}
if conn.Session.ConnectionID == 0 {
t.Error("missing connectionID")
}
r, err := conn.PHIDLookup([]string{"T1", "D1"})
if err != nil {
t.Fatal(err)
}
if r == nil {
t.Fatal("nil response")
}
t.Logf("%+v\n", r)
r2, err := conn.PHIDLookupSingle("D1")
if err != nil {
t.Fatal(err)
}
if r2 == nil {
t.Fatal("nil response")
}
t.Logf("%+v\n", r2)
}