TestHttpRpcServerWithAuthenticate
(t *testing.T)
| 82 | |
| 83 | // TestHttpRpcServerWithAuthenticate |
| 84 | func 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 | |
| 114 | func sendHttpRequest(urlpath, method, body string, paramters, headers map[string]string) []byte { |
| 115 | params := url.Values{} |
nothing calls this directly
no test coverage detected