-
Notifications
You must be signed in to change notification settings - Fork 300
/
bug_test.go
66 lines (50 loc) · 1.28 KB
/
bug_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
package kite_test
import (
"errors"
"fmt"
"net/http/httptest"
"testing"
"github.com/koding/kite"
)
func TestKite_MultipleDial(t *testing.T) {
esrv := kite.New("echo-server", "0.0.0")
esrv.Config.DisableAuthentication = true
if err := esrv.Config.ReadEnvironmentVariables(); err != nil {
t.Fatal(err)
}
esrv.HandleFunc("echo", func(r *kite.Request) (interface{}, error) {
var arg string
if err := r.Args.One().Unmarshal(&arg); err != nil {
return nil, err
}
if arg == "" {
return nil, errors.New("arg is empty")
}
return arg, nil
})
ts := httptest.NewServer(esrv)
ecli := kite.New("echo-client", "0.0.0")
if err := ecli.Config.ReadEnvironmentVariables(); err != nil {
t.Fatal(err)
}
esrv.SetLogLevel(kite.DEBUG)
ecli.SetLogLevel(kite.DEBUG)
c := ecli.NewClient(fmt.Sprintf("%s/kite", ts.URL))
if err := c.Dial(); err != nil {
t.Fatalf("dialing echo-server kite error: %s", err)
}
if err := c.Dial(); err != nil {
t.Fatalf("dialing echo-server kite error: %s", err)
}
resp, err := c.Tell("echo", "Hello world!")
if err != nil {
t.Fatalf("Tell()=%s", err)
}
var reply string
if err := resp.Unmarshal(&reply); err != nil {
t.Fatalf("Unmarshal()=%s", err)
}
if reply != "Hello world!" {
t.Fatalf(`got %q, want "Hello world!"`, reply)
}
}