MCPcopy Index your code
hub / github.com/koding/kite / TestProxy

Function TestProxy

tunnelproxy/proxy_test.go:18–106  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

16)
17
18func TestProxy(t *testing.T) {
19 conf := config.New()
20 conf.Username = "testuser"
21 conf.KontrolURL = "ws://localhost:6666/kite"
22 conf.KontrolKey = testkeys.Public
23 conf.KontrolUser = "testuser"
24 conf.KiteKey = testutil.NewKiteKey().Raw
25 conf.Transport = config.WebSocket // tunnel only works via WebSocket
26
27 // start kontrol
28 color.Green("Starting kontrol")
29 kontrol.DefaultPort = 6666
30 kon := kontrol.New(conf.Copy(), "0.1.0")
31
32 switch os.Getenv("KONTROL_STORAGE") {
33 case "etcd":
34 kon.SetStorage(kontrol.NewEtcd(nil, kon.Kite.Log))
35 case "postgres":
36 p := kontrol.NewPostgres(nil, kon.Kite.Log)
37 kon.SetStorage(p)
38 kon.SetKeyPairStorage(p)
39 default:
40 kon.SetStorage(kontrol.NewEtcd(nil, kon.Kite.Log))
41 }
42
43 kon.AddKeyPair("", testkeys.Public, testkeys.Private)
44
45 go kon.Run()
46 <-kon.Kite.ServerReadyNotify()
47
48 DefaultPort = 4999
49 DefaultPublicHost = "localhost:4999"
50 prxConf := conf.Copy()
51 prxConf.DisableAuthentication = true // no kontrol running in test
52 prx := New(prxConf, "0.1.0", testkeys.Public, testkeys.Private)
53 prx.Start()
54
55 log.Println("Proxy started")
56
57 // Proxy kite is ready.
58 kite1 := kite.New("kite1", "1.0.0")
59 kite1.Config = conf.Copy()
60 kite1.HandleFunc("foo", func(r *kite.Request) (interface{}, error) {
61 return "bar", nil
62 })
63
64 prxClt := kite1.NewClient("http://localhost:4999/kite")
65 err := prxClt.Dial()
66 if err != nil {
67 t.Fatal(err)
68 }
69
70 // Kite1 is connected to proxy.
71
72 result, err := prxClt.TellWithTimeout("register", 4*time.Second)
73 if err != nil {
74 t.Fatal(err)
75 }

Callers

nothing calls this directly

Calls 14

DialMethod · 0.95
TellWithTimeoutMethod · 0.95
CopyMethod · 0.80
SetStorageMethod · 0.80
SetKeyPairStorageMethod · 0.80
AddKeyPairMethod · 0.80
ServerReadyNotifyMethod · 0.80
StartMethod · 0.80
HandleFuncMethod · 0.80
NewClientMethod · 0.80
FatalMethod · 0.80
MustStringMethod · 0.80

Tested by

no test coverage detected