MCPcopy Create free account
hub / github.com/baidu-golang/pbrpc / TestHttpRpcServerWithAuthenticate

Function TestHttpRpcServerWithAuthenticate

httpserver_test.go:84–112  ·  view source on GitHub ↗

TestHttpRpcServerWithAuthenticate

(t *testing.T)

Source from the content-addressed store, hash-verified

82
83// TestHttpRpcServerWithAuthenticate
84func TestHttpRpcServerWithAuthenticate(t *testing.T) {
85 Convey("test http rpc with authenticate", t, func() {
86
87 tcpServer := startRpcServerWithHttpMode(0, true)
88 tcpServer.SetAuthService(new(StringMatchAuthService))
89 tcpServer.SetTraceService(new(AddOneTraceService))
90 defer stopRpcServer(tcpServer)
91
92 sport := strconv.Itoa(PORT_1)
93 urlpath := "http://localhost:" + sport + "/rpc/EchoService/echo"
94 paramters := map[string]string{}
95 headers := map[string]string{}
96 headers[baidurpc.Auth_key] = AUTH_TOKEN
97 headers[baidurpc.LogId_key] = "1"
98
99 headers[baidurpc.Trace_Id_key] = "1"
100 headers[baidurpc.Trace_Span_key] = "2"
101 headers[baidurpc.Trace_Parent_key] = "3"
102
103 result := sendHttpRequest(urlpath, "POST", "{\"name\":\"matt\"}", paramters, headers)
104
105 So(result, ShouldNotBeNil)
106 data := &baidurpc.ResponseData{}
107 err := json.Unmarshal(result, data)
108 So(err, ShouldBeNil)
109 So(data.ErrNo, ShouldEqual, 0)
110
111 })
112}
113
114func sendHttpRequest(urlpath, method, body string, paramters, headers map[string]string) []byte {
115 params := url.Values{}

Callers

nothing calls this directly

Calls 5

sendHttpRequestFunction · 0.85
SetAuthServiceMethod · 0.80
SetTraceServiceMethod · 0.80
stopRpcServerFunction · 0.70

Tested by

no test coverage detected