-
Notifications
You must be signed in to change notification settings - Fork 34
/
Copy pathutil_test.go
69 lines (59 loc) · 1.51 KB
/
util_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
package main
import(
zmq "github.com/pebbe/zmq4"
"fmt"
"code.google.com/p/go-uuid/uuid"
"os/exec"
"io/ioutil"
)
//
// Responders
//
func _test_string_responder() {
routeid := "GET/_/test_string"
responder, _ := zmq.NewSocket(zmq.REQ)
defer responder.Close()
identity := uuid.New()
responder.SetIdentity(identity)
responder.Connect("tcp://localhost:4321")
responder.Send(routeid, 0)
for {
_, err := responder.RecvMessage(0)
if err != nil {
fmt.Println("Error in receiving message:", err)
break // Interrupted
}
resp := []string{"200", "{\"Content-Type\": \"text/html\"}", "Hello World",}
responder.SendMessage(routeid, resp)
}
}
func _test_json_responder() {
routeid := "GET/_/test_json"
responder, _ := zmq.NewSocket(zmq.REQ)
defer responder.Close()
identity := uuid.New()
responder.SetIdentity(identity)
responder.Connect("tcp://localhost:4321")
responder.Send(routeid, 0)
json := _read_sample_json()
for {
_, err := responder.RecvMessage(0)
if err != nil {
fmt.Println("Error in receiving message:", err)
break // Interrupted
}
resp := []string{"200", "{\"Content-Type\": \"application/json\"}", json,}
responder.SendMessage(routeid, resp)
}
}
func _start_broker() {
broker := exec.Command("go run ./broker/broker.go")
broker.Start()
}
func _read_sample_json() string {
json_bytes, err := ioutil.ReadFile("./testdata/sample.json")
if err != nil {
fmt.Println("Error in reading sample json", err)
}
return string(json_bytes)
}