MCPcopy
hub / github.com/davyxu/cellnet / TestHttp

Function TestHttp

tests/http_test.go:18–63  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

16const httpTestAddr = "127.0.0.1:8081"
17
18func TestHttp(t *testing.T) {
19
20 p := peer.NewGenericPeer("http.Acceptor", "httpserver", httpTestAddr, nil)
21
22 proc.BindProcessorHandler(p, "http", func(raw cellnet.Event) {
23
24 if matcher, ok := raw.Session().(httppeer.RequestMatcher); ok {
25 switch {
26 case matcher.Match("GET", "/hello_get"):
27
28 // 默认返回json
29 raw.Session().Send(&httppeer.MessageRespond{
30 Msg: &HttpEchoACK{
31 Token: "get",
32 },
33 })
34 case matcher.Match("POST", "/hello_post"):
35
36 // 默认返回json
37 raw.Session().Send(&httppeer.MessageRespond{
38 Msg: &HttpEchoACK{
39 Token: "post",
40 },
41 })
42
43 }
44 }
45
46 })
47
48 p.Start()
49
50 requestThenValid(t, "GET", "/hello_get", &HttpEchoREQ{
51 UserName: "kitty_get",
52 }, &HttpEchoACK{
53 Token: "get",
54 })
55
56 requestThenValid(t, "POST", "/hello_post", &HttpEchoREQ{
57 UserName: "kitty_post",
58 }, &HttpEchoACK{
59 Token: "post",
60 })
61
62 p.Stop()
63}
64
65func requestThenValid(t *testing.T, method, path string, req, expectACK interface{}) {
66

Callers

nothing calls this directly

Calls 8

NewGenericPeerFunction · 0.92
BindProcessorHandlerFunction · 0.92
requestThenValidFunction · 0.85
SessionMethod · 0.65
MatchMethod · 0.65
SendMethod · 0.65
StartMethod · 0.65
StopMethod · 0.65

Tested by

no test coverage detected