update to latest micro-server-http
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
@@ -8,6 +8,7 @@ import (
|
|||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"mime/multipart"
|
"mime/multipart"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"net/http/httptest"
|
||||||
"net/url"
|
"net/url"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
@@ -217,7 +218,13 @@ func (h *Handler) Call(ctx context.Context, req *pb.CallReq, rsp *pb.CallRsp) er
|
|||||||
|
|
||||||
func (h *Handler) CallError(ctx context.Context, req *pb.CallReq1, rsp *pb.CallRsp1) error {
|
func (h *Handler) CallError(ctx context.Context, req *pb.CallReq1, rsp *pb.CallRsp1) error {
|
||||||
httpsrv.SetRspCode(ctx, http.StatusBadRequest)
|
httpsrv.SetRspCode(ctx, http.StatusBadRequest)
|
||||||
return httpsrv.SetError(&pb.Error{Msg: "my_error"})
|
switch req.Name {
|
||||||
|
case "my_name":
|
||||||
|
return httpsrv.SetError(&pb.Error{Msg: "my_error"})
|
||||||
|
case "my_name_test":
|
||||||
|
return httpsrv.SetError(&pb.Error{Msg: "my_error_test"})
|
||||||
|
}
|
||||||
|
return httpsrv.SetError(&pb.Error{Msg: "unknown"})
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestNativeFormUrlencoded(t *testing.T) {
|
func TestNativeFormUrlencoded(t *testing.T) {
|
||||||
@@ -510,6 +517,15 @@ func TestNativeServer(t *testing.T) {
|
|||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if err := srv.Init(); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn, err := srv.HTTPHandlerFunc(h.CallError)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
// start server
|
// start server
|
||||||
if err := srv.Start(); err != nil {
|
if err := srv.Start(); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
@@ -580,6 +596,19 @@ func TestNativeServer(t *testing.T) {
|
|||||||
t.Fatalf("Expected response %s, got %s", `{"msg":"my_error"}`, s)
|
t.Fatalf("Expected response %s, got %s", `{"msg":"my_error"}`, s)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
rr := httptest.NewRecorder()
|
||||||
|
rq, err := http.NewRequestWithContext(context.TODO(), http.MethodPost, "/v1/test/callerror/my_name_test", nil)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
fn(rr, rq)
|
||||||
|
if rr.Code != http.StatusBadRequest {
|
||||||
|
t.Fatalf("invalid status received: %s\n", rr.Body.String())
|
||||||
|
}
|
||||||
|
if s := rr.Body.String(); s != `{"msg":"my_error_test"}` {
|
||||||
|
t.Fatalf("Expected response %s, got %s", `{"msg":"my_error_test"}`, s)
|
||||||
|
}
|
||||||
|
|
||||||
rsp, err = http.Post(fmt.Sprintf("http://%s/v1/test/call_repeated_string?string_ids=123&string_ids=321", service[0].Nodes[0].Address), "application/json", nil)
|
rsp, err = http.Post(fmt.Sprintf("http://%s/v1/test/call_repeated_string?string_ids=123&string_ids=321", service[0].Nodes[0].Address), "application/json", nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
|
Reference in New Issue
Block a user