forked from trustmaster/goflow
/
runtime_test.go
57 lines (53 loc) · 1.29 KB
/
runtime_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
package flow
import (
"code.google.com/p/go.net/websocket"
"testing"
)
var (
r *Runtime
started bool
)
func ensureRuntimeStarted() {
if !started {
r = new(Runtime)
r.Init("goflow")
go r.Listen("localhost:13014")
started = true
<-r.Ready()
}
}
// Tests runtime information support
func TestRuntimeGetRuntime(t *testing.T) {
ensureRuntimeStarted()
// Create a WebSocket client
ws, err := websocket.Dial("ws://localhost:13014/", "", "http://localhost/")
if err != nil {
t.Error(err.Error())
}
// Send a runtime request and check the response
if err = websocket.JSON.Send(ws, &Message{"runtime", "getruntime", nil}); err != nil {
t.Error(err.Error())
}
var msg runtimeMessage
if err = websocket.JSON.Receive(ws, &msg); err != nil {
t.Error(err.Error())
return
}
if msg.Protocol != "runtime" || msg.Command != "runtime" {
t.Errorf("Invalid protocol (%s) or command (%s)", msg.Protocol, msg.Command)
return
}
res := msg.Payload
if res.Type != "goflow" {
t.Errorf("Invalid protocol type: %s\n", res.Type)
}
if res.Version != "0.4" {
t.Errorf("Invalid protocol version: %s\n", res.Version)
}
if len(res.Capabilities) != 5 {
t.Errorf("Invalid number of supported capabilities: %v\n", res.Capabilities)
}
if res.Id == "" {
t.Error("Runtime Id is empty")
}
}