update deps #55
@ -143,7 +143,7 @@ func TestGRPCClient(t *testing.T) {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 500*time.Millisecond)
|
||||
defer cancel()
|
||||
|
||||
req := c.NewRequest("helloworld", "Test.Stream", &pb.Request{}, client.StreamingRequest())
|
||||
req := c.NewRequest("helloworld", "Test.Stream", &pb.Request{}, client.StreamingRequest(true))
|
||||
stream, err := c.Stream(ctx, req)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
|
11
go.mod
11
go.mod
@ -8,12 +8,12 @@ require (
|
||||
github.com/prometheus/client_golang v1.10.0
|
||||
github.com/prometheus/client_model v0.2.0
|
||||
github.com/stretchr/testify v1.7.0
|
||||
github.com/unistack-org/micro-api-handler-rpc/v3 v3.2.0
|
||||
github.com/unistack-org/micro-api-handler-rpc/v3 v3.3.0
|
||||
github.com/unistack-org/micro-api-router-register/v3 v3.2.2
|
||||
github.com/unistack-org/micro-api-router-static/v3 v3.2.1
|
||||
github.com/unistack-org/micro-broker-http/v3 v3.3.0
|
||||
github.com/unistack-org/micro-client-grpc/v3 v3.2.4
|
||||
github.com/unistack-org/micro-client-http/v3 v3.3.3
|
||||
github.com/unistack-org/micro-client-http/v3 v3.3.4
|
||||
github.com/unistack-org/micro-codec-grpc/v3 v3.1.1
|
||||
github.com/unistack-org/micro-codec-json/v3 v3.1.1
|
||||
github.com/unistack-org/micro-codec-jsonpb/v3 v3.1.1
|
||||
@ -26,10 +26,10 @@ require (
|
||||
github.com/unistack-org/micro-proto v0.0.2-0.20210227213711-77c7563bd01e
|
||||
github.com/unistack-org/micro-router-register/v3 v3.2.2
|
||||
github.com/unistack-org/micro-server-grpc/v3 v3.3.0
|
||||
github.com/unistack-org/micro-server-http/v3 v3.3.2
|
||||
github.com/unistack-org/micro-server-http/v3 v3.3.3
|
||||
github.com/unistack-org/micro-server-tcp/v3 v3.3.0
|
||||
github.com/unistack-org/micro-wrapper-trace-opentracing/v3 v3.2.0
|
||||
github.com/unistack-org/micro/v3 v3.3.11
|
||||
github.com/unistack-org/micro/v3 v3.3.13
|
||||
google.golang.org/genproto v0.0.0-20210406143921-e86de6bf7a46
|
||||
google.golang.org/grpc v1.36.1
|
||||
google.golang.org/protobuf v1.26.0
|
||||
@ -39,6 +39,9 @@ require (
|
||||
//replace github.com/unistack-org/micro-client-grpc/v3 => ../micro-client-grpc
|
||||
//replace github.com/unistack-org/micro-server-grpc/v3 => ../micro-server-grpc
|
||||
//replace github.com/unistack-org/micro-server-http/v3 => ../micro-server-http
|
||||
|
||||
//replace github.com/unistack-org/micro-client-http/v3 => ../micro-client-http
|
||||
|
||||
//replace github.com/unistack-org/micro/v3 => ../micro
|
||||
|
||||
//replace github.com/unistack-org/micro-proto => ../micro-proto
|
||||
|
26
go.sum
26
go.sum
@ -123,7 +123,6 @@ github.com/go-logfmt/logfmt v0.5.0/go.mod h1:wCYkCAKZfumFQihp8CzCvQ3paCTfi41vtzG
|
||||
github.com/go-sql-driver/mysql v1.4.0/go.mod h1:zAC/RDZ24gD3HViQzih4MyKcchzm+sOG5ZlKdlhCg5w=
|
||||
github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY=
|
||||
github.com/go-test/deep v1.0.2-0.20181118220953-042da051cf31/go.mod h1:wGDj63lr65AM2AQyKZd/NYHGb0R+1RLqB8NKt3aSFNA=
|
||||
github.com/go-test/deep v1.0.7/go.mod h1:QV8Hv/iy04NyLBxAdO9njL0iVPN1S4d/A3NVv1V36o8=
|
||||
github.com/gobwas/httphead v0.1.0 h1:exrUm0f4YX0L7EBwZHuCF4GDp8aJfVeBrlLQrs6NqWU=
|
||||
github.com/gobwas/httphead v0.1.0/go.mod h1:O/RXo79gxV8G+RqlR/otEwx4Q36zl9rqC5u12GKvMCM=
|
||||
github.com/gobwas/pool v0.2.1 h1:xfeeEhW7pwmX8nuLVlqbzVc7udMDrwetjEv+TZIz1og=
|
||||
@ -241,7 +240,6 @@ github.com/hashicorp/vault/sdk v0.1.13 h1:mOEPeOhT7jl0J4AMl1E705+BcmeRs1VmKNb9F0
|
||||
github.com/hashicorp/vault/sdk v0.1.13/go.mod h1:B+hVj7TpuQY1Y/GPbCpffmgd+tSEwvhkWnjtSYCaS2M=
|
||||
github.com/hashicorp/yamux v0.0.0-20180604194846-3520598351bb/go.mod h1:+NfK9FKeTrX5uv1uIXGdwYDTeHna2qgaIlx54MXqjAM=
|
||||
github.com/hashicorp/yamux v0.0.0-20181012175058-2f1d1f20f75d/go.mod h1:+NfK9FKeTrX5uv1uIXGdwYDTeHna2qgaIlx54MXqjAM=
|
||||
github.com/heimdalr/dag v1.0.1/go.mod h1:t+ZkR+sjKL4xhlE1B9rwpvwfo+x+2R0363efS+Oghns=
|
||||
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
|
||||
github.com/hudl/fargo v1.3.0/go.mod h1:y3CKSmjA+wD2gak7sUSXTAoopbhU08POFhmITJgmKTg=
|
||||
github.com/iij/doapi v0.0.0-20190504054126-0bbf12d6d7df/go.mod h1:QMZY7/J/KSQEhKWFeDesPjMj+wCHReeknARU3wqlyN4=
|
||||
@ -446,8 +444,8 @@ github.com/timewasted/linode v0.0.0-20160829202747-37e84520dcf7/go.mod h1:imsgLp
|
||||
github.com/tmc/grpc-websocket-proxy v0.0.0-20170815181823-89b8d40f7ca8/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U=
|
||||
github.com/transip/gotransip v0.0.0-20190812104329-6d8d9179b66f/go.mod h1:i0f4R4o2HM0m3DZYQWsj6/MEowD57VzoH0v3d7igeFY=
|
||||
github.com/uber-go/atomic v1.3.2/go.mod h1:/Ct5t2lcmbJ4OSe/waGBoaVvVqtO0bmtfVNex1PFV8g=
|
||||
github.com/unistack-org/micro-api-handler-rpc/v3 v3.2.0 h1:+tbmvhA6QtGPgHLeaI/1LevPLkQ4wLb8iBqNmWeoHIs=
|
||||
github.com/unistack-org/micro-api-handler-rpc/v3 v3.2.0/go.mod h1:24qiRO0ruGqzTGq/ncygnjFar3i3xbsWNTNjE+PQKS8=
|
||||
github.com/unistack-org/micro-api-handler-rpc/v3 v3.3.0 h1:u+uobYW44rfHSQ8HfRs2kHzoG2SJcjDii/NRSnB3UXg=
|
||||
github.com/unistack-org/micro-api-handler-rpc/v3 v3.3.0/go.mod h1:Y3EVOGcYCDMJCvoCbW2v/RRunGuvR9fT/pjRZeDcvFQ=
|
||||
github.com/unistack-org/micro-api-router-register/v3 v3.2.2 h1:O8tIP+NFqyp/3F8vYnDMTati4etc2URxUSUH1VrEqOY=
|
||||
github.com/unistack-org/micro-api-router-register/v3 v3.2.2/go.mod h1:MZeqvmekQB/avrTRajp86+s7GuHkQ8HAee+hZtY+dWw=
|
||||
github.com/unistack-org/micro-api-router-static/v3 v3.2.1 h1:FMcEb8NYYX72OyQuMKHbtdEQV+eOFbmKyvwSY8cgan8=
|
||||
@ -456,8 +454,8 @@ github.com/unistack-org/micro-broker-http/v3 v3.3.0 h1:IjdBtcmxl4OniyHG+FAkNoZS9
|
||||
github.com/unistack-org/micro-broker-http/v3 v3.3.0/go.mod h1:soBy700MUOHV5YcyIG949uxqd+FMUinQQr+Qi7ilE4A=
|
||||
github.com/unistack-org/micro-client-grpc/v3 v3.2.4 h1:pz6GI4hxko167zB6mjwyiPvVJpgtdTY0GhiwNHkZ8N8=
|
||||
github.com/unistack-org/micro-client-grpc/v3 v3.2.4/go.mod h1:0yMOc4qT+a1qYK2nIL+zV7FEmP3CNqDajw4lZ7D/08E=
|
||||
github.com/unistack-org/micro-client-http/v3 v3.3.3 h1:rh6B/QPqmZ16OpZ/DoWYJ4IG34Qr3L/3qzHM5Fyh+NM=
|
||||
github.com/unistack-org/micro-client-http/v3 v3.3.3/go.mod h1:bYHYQlZILimIN2quZJimnF8/cM5IsVQe8Y51yc2za5M=
|
||||
github.com/unistack-org/micro-client-http/v3 v3.3.4 h1:kc3F+GeUVOTAFOoW8J5Ve1NYTT/QLTMNQ+g/Z1+2zME=
|
||||
github.com/unistack-org/micro-client-http/v3 v3.3.4/go.mod h1:mHKBBipPJLP4/ejoh3PE/lo6QRpH+XYh1qJXnL55t6w=
|
||||
github.com/unistack-org/micro-codec-grpc/v3 v3.1.1 h1:h+x6ny1UeMEqZWPx7vhkfczetnFh00lbCxdLl9Rr0EU=
|
||||
github.com/unistack-org/micro-codec-grpc/v3 v3.1.1/go.mod h1:2iY/1jF+gnRGwZZBz7PU9pN7DIERWh5mnz2xwQtwm1M=
|
||||
github.com/unistack-org/micro-codec-json/v3 v3.1.1 h1:1iILAzvT7XP7Dxae9yfZJwId0nVA9GZc3Ez+n2iF3tc=
|
||||
@ -482,8 +480,8 @@ github.com/unistack-org/micro-router-register/v3 v3.2.2 h1:lYCymDHkJfhZWYQ4+Sb7F
|
||||
github.com/unistack-org/micro-router-register/v3 v3.2.2/go.mod h1:Y9Qtlg4NHqq5rR6X6Jm+04LoSJMi7/OOCm2mRueZYTE=
|
||||
github.com/unistack-org/micro-server-grpc/v3 v3.3.0 h1:iHKWqX5p747pLEiTJKdNBMYBhrkZOeyPvEw1y15wF7k=
|
||||
github.com/unistack-org/micro-server-grpc/v3 v3.3.0/go.mod h1:dXEZ/hWrdgS4o3BrOMsiUiuyPJSPdhs1qWXELezcOAw=
|
||||
github.com/unistack-org/micro-server-http/v3 v3.3.2 h1:RDp7M/W1nmMtWRU3qAESzAIfDLBgUwbpQB/tIKiOXsM=
|
||||
github.com/unistack-org/micro-server-http/v3 v3.3.2/go.mod h1:iN0AZoV+iIFL4f1C6HnGEWaPrSgBCaYwv7ti41PFH6k=
|
||||
github.com/unistack-org/micro-server-http/v3 v3.3.3 h1:XO66LEbZnT3nICMH+3cOSkpRolekBgQh27HwkQkUAMA=
|
||||
github.com/unistack-org/micro-server-http/v3 v3.3.3/go.mod h1:x+GIBcR0k/a4TqQpr8gixYHNbfc5qsqpYsozh2vbo5o=
|
||||
github.com/unistack-org/micro-server-tcp/v3 v3.3.0 h1:YIj5SvuPm7Q0CTo/L8ALcQFoBHwiGrz33TxvpcPuXYI=
|
||||
github.com/unistack-org/micro-server-tcp/v3 v3.3.0/go.mod h1:3cxrSzkmrHOkWuYvi7dAK+gAsuO6EkxoT9Y0LUNhC3I=
|
||||
github.com/unistack-org/micro-wrapper-trace-opentracing/v3 v3.2.0 h1:PvemkpeCVUWfCoKwt1XmJ8uGK9My/7T29qOVxtYJohw=
|
||||
@ -492,14 +490,14 @@ github.com/unistack-org/micro/v3 v3.1.1/go.mod h1:0DgOy4OdJxQCDER8YSKitZugd2+1bd
|
||||
github.com/unistack-org/micro/v3 v3.2.1/go.mod h1:J8XxJj4Pqa3Ee0a4biRRtut7UwTlfBq8QRe+s4PKGS0=
|
||||
github.com/unistack-org/micro/v3 v3.2.2/go.mod h1:J8XxJj4Pqa3Ee0a4biRRtut7UwTlfBq8QRe+s4PKGS0=
|
||||
github.com/unistack-org/micro/v3 v3.2.11/go.mod h1:uGPB8BhDWHj63tR3eaoCd3X+lPtAgFG630897yhB3Ag=
|
||||
github.com/unistack-org/micro/v3 v3.2.14/go.mod h1:3j13mSd/rILNjyP0tEVtDxyDkJBtnHUXShNCuPHkC5A=
|
||||
github.com/unistack-org/micro/v3 v3.2.22/go.mod h1:oI8H/uGq1h4i5cvUycEoFKJQC7G8yChZQNIDNWGSLRU=
|
||||
github.com/unistack-org/micro/v3 v3.2.24/go.mod h1:iJwCWq2PECMxigfqe6TPC5GLWvj6P94Kk+PTVZGL3w8=
|
||||
github.com/unistack-org/micro/v3 v3.3.0/go.mod h1:iJwCWq2PECMxigfqe6TPC5GLWvj6P94Kk+PTVZGL3w8=
|
||||
github.com/unistack-org/micro/v3 v3.3.9/go.mod h1:M3RGgKZX1OlTn0QB+3R1tlSoGwmEg6rb/Isr0lLYmjQ=
|
||||
github.com/unistack-org/micro/v3 v3.3.10/go.mod h1:5ragE2E8ER5d4FZQJG9pB6qdfOoLXLfKW89l77Dy3jQ=
|
||||
github.com/unistack-org/micro/v3 v3.3.11 h1:Jr0gAw5lLqgddiHKQeWUOUeP6ZqgRhz52EA9zJ5MJ3U=
|
||||
github.com/unistack-org/micro/v3 v3.3.11/go.mod h1:PPCt675o3HPcODFbJ4iRWPmQFAk1WQ+asQSOb/syq6U=
|
||||
github.com/unistack-org/micro/v3 v3.3.12/go.mod h1:98hNcMXp/WyWJwLwCuwrhN1Jm7aCWaRNsMfRjK8Fq+Y=
|
||||
github.com/unistack-org/micro/v3 v3.3.13 h1:y4bDDkbwnjgOckrhFkC6D/o42tr75X33UbrB+Ko0M68=
|
||||
github.com/unistack-org/micro/v3 v3.3.13/go.mod h1:98hNcMXp/WyWJwLwCuwrhN1Jm7aCWaRNsMfRjK8Fq+Y=
|
||||
github.com/urfave/cli v1.20.0/go.mod h1:70zkFmudgCuE/ngEzBv17Jvp/497gISqfk5gWijbERA=
|
||||
github.com/urfave/cli v1.22.1/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0=
|
||||
github.com/valyala/fastrand v1.0.0 h1:LUKT9aKer2dVQNUi3waewTbKV+7H17kvWFNKs2ObdkI=
|
||||
@ -596,11 +594,10 @@ golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v
|
||||
golang.org/x/net v0.0.0-20210316092652-d523dce5a7f4/go.mod h1:RBQZq4jEuRlivfhVLdyRGr576XBO4/greRjx4P4O3yc=
|
||||
golang.org/x/net v0.0.0-20210323141857-08027d57d8cf/go.mod h1:RBQZq4jEuRlivfhVLdyRGr576XBO4/greRjx4P4O3yc=
|
||||
golang.org/x/net v0.0.0-20210324051636-2c4c8ecb7826/go.mod h1:RBQZq4jEuRlivfhVLdyRGr576XBO4/greRjx4P4O3yc=
|
||||
golang.org/x/net v0.0.0-20210326220855-61e056675ecf/go.mod h1:uSPa2vr4CLtc/ILN5odXGNXS6mhrKVzTaCXzk9m6W3k=
|
||||
golang.org/x/net v0.0.0-20210330142815-c8897c278d10/go.mod h1:uSPa2vr4CLtc/ILN5odXGNXS6mhrKVzTaCXzk9m6W3k=
|
||||
golang.org/x/net v0.0.0-20210331060903-cb1fcc7394e5/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM=
|
||||
golang.org/x/net v0.0.0-20210331212208-0fccb6fa2b5c h1:KHUzaHIpjWVlVVNh65G3hhuj3KB1HnjY6Cq5cTvRQT8=
|
||||
golang.org/x/net v0.0.0-20210331212208-0fccb6fa2b5c/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM=
|
||||
golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4 h1:4nGaVu0QrbjT/AK2PRLuQfQuh6DJve+pELhqTdAj3x0=
|
||||
golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM=
|
||||
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
|
||||
golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
|
||||
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
|
||||
@ -650,7 +647,6 @@ golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c/go.mod h1:h1NjWce9XRLGQEsW7w
|
||||
golang.org/x/sys v0.0.0-20210309074719-68d13333faf2/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20210315160823-c6e025ad8005/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20210320140829-1e4c9ba3b0c4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20210324051608-47abb6519492/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44 h1:Bli41pIlzTzf3KEY06n+xnzK/BESIg2ze4Pgfh/aI8c=
|
||||
golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw=
|
||||
|
@ -7,6 +7,7 @@ import (
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
@ -76,6 +77,108 @@ func (h *Handler) CallError(ctx context.Context, req *pb.CallReq1, rsp *pb.CallR
|
||||
return httpsrv.SetError(&pb.Error{Msg: "my_error"})
|
||||
}
|
||||
|
||||
func TestNativeFormUrlencoded(t *testing.T) {
|
||||
reg := register.NewRegister()
|
||||
ctx := context.Background()
|
||||
|
||||
// create server
|
||||
srv := httpsrv.NewServer(
|
||||
server.Name("helloworld"),
|
||||
server.Register(reg),
|
||||
server.Codec("application/json", jsoncodec.NewCodec()),
|
||||
//server.WrapHandler(NewServerHandlerWrapper()),
|
||||
)
|
||||
|
||||
if err := srv.Init(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
h := &Handler{t: t}
|
||||
pb.RegisterTestServer(srv, h)
|
||||
|
||||
// start server
|
||||
if err := srv.Start(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
// lookup server
|
||||
service, err := reg.LookupService(ctx, "helloworld")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if len(service) != 1 {
|
||||
t.Fatalf("Expected 1 service got %d: %+v", len(service), service)
|
||||
}
|
||||
|
||||
if len(service[0].Nodes) != 1 {
|
||||
t.Fatalf("Expected 1 node got %d: %+v", len(service[0].Nodes), service[0].Nodes)
|
||||
}
|
||||
|
||||
t.Logf("test net/http client with application/x-www-form-urlencoded")
|
||||
data := url.Values{}
|
||||
data.Set("req", "fookey")
|
||||
data.Set("arg1", "arg1val")
|
||||
data.Add("nested.uint64_args", "1")
|
||||
data.Add("nested.uint64_args", "2")
|
||||
data.Add("nested.uint64_args", "3")
|
||||
// make request
|
||||
req, err := http.NewRequest(http.MethodPost, fmt.Sprintf("http://%s/v1/test/call/my_name", service[0].Nodes[0].Address), strings.NewReader(data.Encode())) // URL-encoded payload
|
||||
req.Header.Add("Content-Type", "application/x-www-form-urlencoded")
|
||||
//req.Header.Add("Content-Length", strconv.Itoa(len(data.Encode())))
|
||||
|
||||
rsp, err := http.DefaultClient.Do(req)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
b, err := ioutil.ReadAll(rsp.Body)
|
||||
rsp.Body.Close()
|
||||
|
||||
if err != nil && err != io.EOF {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if rsp.StatusCode != http.StatusCreated {
|
||||
t.Fatalf("invalid status received: %#+v\n%s\n", rsp, b)
|
||||
}
|
||||
|
||||
if s := string(b); s != `{"rsp":"name_my_name"}` {
|
||||
t.Fatalf("Expected response %s, got %s", `{"rsp":"name_my_name"}`, s)
|
||||
}
|
||||
|
||||
if v := rsp.Header.Get("My-Key"); v != "my-val" {
|
||||
t.Fatalf("empty response header: %#+v", rsp.Header)
|
||||
}
|
||||
|
||||
t.Logf("test native client with application/x-www-form-urlencoded")
|
||||
cli := client.NewClientCallOptions(httpcli.NewClient(client.ContentType("application/x-www-form-urlencoded"), client.Codec("application/json", jsonpbcodec.
|
||||
NewCodec())), client.WithAddress(fmt.Sprintf("http://%s", service[0].Nodes[0].Address)))
|
||||
|
||||
svc1 := pb.NewTestClient("helloworld", cli)
|
||||
nrsp, err := svc1.Call(ctx, &pb.CallReq{
|
||||
Name: "my_name",
|
||||
Arg1: "arg1val",
|
||||
Nested: &pb.Nested{Uint64Args: []*wrapperspb.UInt64Value{
|
||||
&wrapperspb.UInt64Value{Value: 1},
|
||||
&wrapperspb.UInt64Value{Value: 2},
|
||||
&wrapperspb.UInt64Value{Value: 3},
|
||||
}},
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if nrsp.Rsp != "name_my_name" {
|
||||
t.Fatalf("invalid response: %#+v\n", nrsp)
|
||||
}
|
||||
|
||||
// stop server
|
||||
if err := srv.Stop(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func TestNativeClientServer(t *testing.T) {
|
||||
reg := register.NewRegister()
|
||||
ctx := context.Background()
|
||||
@ -259,7 +362,7 @@ func TestNativeServer(t *testing.T) {
|
||||
}
|
||||
|
||||
// make request
|
||||
rsp, err := http.Post(fmt.Sprintf("http://%s/v1/test/call/my_name?req=key&arg1=arg1&arg2=12345&nested.string_args=str1,str2&nested.uint64_args=1,2,3", service[0].Nodes[0].Address), "application/json", nil)
|
||||
rsp, err := http.Post(fmt.Sprintf("http://%s/v1/test/call/my_name?req=key&arg1=arg1&arg2=12345&nested.string_args=str1&nested.string_args=str2&nested.uint64_args=1&nested.uint64_args=2&nested.uint64_args=3", service[0].Nodes[0].Address), "application/json", nil)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
3
util/reflect/generate.go
Normal file
3
util/reflect/generate.go
Normal file
@ -0,0 +1,3 @@
|
||||
package reflect
|
||||
|
||||
//go:generate protoc -I./proto --go_out=paths=source_relative:./proto proto/test.proto
|
263
util/reflect/proto/test.pb.go
Normal file
263
util/reflect/proto/test.pb.go
Normal file
@ -0,0 +1,263 @@
|
||||
// Code generated by protoc-gen-go. DO NOT EDIT.
|
||||
// versions:
|
||||
// protoc-gen-go v1.26.0
|
||||
// protoc v3.15.6
|
||||
// source: test.proto
|
||||
|
||||
package pb
|
||||
|
||||
import (
|
||||
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
|
||||
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
|
||||
wrapperspb "google.golang.org/protobuf/types/known/wrapperspb"
|
||||
reflect "reflect"
|
||||
sync "sync"
|
||||
)
|
||||
|
||||
const (
|
||||
// Verify that this generated code is sufficiently up-to-date.
|
||||
_ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion)
|
||||
// Verify that runtime/protoimpl is sufficiently up-to-date.
|
||||
_ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20)
|
||||
)
|
||||
|
||||
type CallReq struct {
|
||||
state protoimpl.MessageState
|
||||
sizeCache protoimpl.SizeCache
|
||||
unknownFields protoimpl.UnknownFields
|
||||
|
||||
Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"`
|
||||
Req string `protobuf:"bytes,2,opt,name=req,proto3" json:"req,omitempty"`
|
||||
Arg1 string `protobuf:"bytes,3,opt,name=arg1,proto3" json:"arg1,omitempty"`
|
||||
Arg2 uint64 `protobuf:"varint,4,opt,name=arg2,proto3" json:"arg2,omitempty"`
|
||||
Nested *Nested `protobuf:"bytes,5,opt,name=nested,proto3" json:"nested,omitempty"`
|
||||
}
|
||||
|
||||
func (x *CallReq) Reset() {
|
||||
*x = CallReq{}
|
||||
if protoimpl.UnsafeEnabled {
|
||||
mi := &file_test_proto_msgTypes[0]
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
}
|
||||
|
||||
func (x *CallReq) String() string {
|
||||
return protoimpl.X.MessageStringOf(x)
|
||||
}
|
||||
|
||||
func (*CallReq) ProtoMessage() {}
|
||||
|
||||
func (x *CallReq) ProtoReflect() protoreflect.Message {
|
||||
mi := &file_test_proto_msgTypes[0]
|
||||
if protoimpl.UnsafeEnabled && x != nil {
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
if ms.LoadMessageInfo() == nil {
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
return ms
|
||||
}
|
||||
return mi.MessageOf(x)
|
||||
}
|
||||
|
||||
// Deprecated: Use CallReq.ProtoReflect.Descriptor instead.
|
||||
func (*CallReq) Descriptor() ([]byte, []int) {
|
||||
return file_test_proto_rawDescGZIP(), []int{0}
|
||||
}
|
||||
|
||||
func (x *CallReq) GetName() string {
|
||||
if x != nil {
|
||||
return x.Name
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (x *CallReq) GetReq() string {
|
||||
if x != nil {
|
||||
return x.Req
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (x *CallReq) GetArg1() string {
|
||||
if x != nil {
|
||||
return x.Arg1
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (x *CallReq) GetArg2() uint64 {
|
||||
if x != nil {
|
||||
return x.Arg2
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func (x *CallReq) GetNested() *Nested {
|
||||
if x != nil {
|
||||
return x.Nested
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
type Nested struct {
|
||||
state protoimpl.MessageState
|
||||
sizeCache protoimpl.SizeCache
|
||||
unknownFields protoimpl.UnknownFields
|
||||
|
||||
StringArgs []string `protobuf:"bytes,1,rep,name=string_args,json=stringArgs,proto3" json:"string_args,omitempty"`
|
||||
Uint64Args []*wrapperspb.UInt64Value `protobuf:"bytes,2,rep,name=uint64_args,json=uint64Args,proto3" json:"uint64_args,omitempty"`
|
||||
}
|
||||
|
||||
func (x *Nested) Reset() {
|
||||
*x = Nested{}
|
||||
if protoimpl.UnsafeEnabled {
|
||||
mi := &file_test_proto_msgTypes[1]
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
}
|
||||
|
||||
func (x *Nested) String() string {
|
||||
return protoimpl.X.MessageStringOf(x)
|
||||
}
|
||||
|
||||
func (*Nested) ProtoMessage() {}
|
||||
|
||||
func (x *Nested) ProtoReflect() protoreflect.Message {
|
||||
mi := &file_test_proto_msgTypes[1]
|
||||
if protoimpl.UnsafeEnabled && x != nil {
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
if ms.LoadMessageInfo() == nil {
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
return ms
|
||||
}
|
||||
return mi.MessageOf(x)
|
||||
}
|
||||
|
||||
// Deprecated: Use Nested.ProtoReflect.Descriptor instead.
|
||||
func (*Nested) Descriptor() ([]byte, []int) {
|
||||
return file_test_proto_rawDescGZIP(), []int{1}
|
||||
}
|
||||
|
||||
func (x *Nested) GetStringArgs() []string {
|
||||
if x != nil {
|
||||
return x.StringArgs
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (x *Nested) GetUint64Args() []*wrapperspb.UInt64Value {
|
||||
if x != nil {
|
||||
return x.Uint64Args
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
var File_test_proto protoreflect.FileDescriptor
|
||||
|
||||
var file_test_proto_rawDesc = []byte{
|
||||
0x0a, 0x0a, 0x74, 0x65, 0x73, 0x74, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x07, 0x72, 0x65,
|
||||
0x66, 0x6c, 0x65, 0x63, 0x74, 0x1a, 0x1e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2f, 0x70, 0x72,
|
||||
0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2f, 0x77, 0x72, 0x61, 0x70, 0x70, 0x65, 0x72, 0x73, 0x2e,
|
||||
0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x80, 0x01, 0x0a, 0x07, 0x43, 0x61, 0x6c, 0x6c, 0x52, 0x65,
|
||||
0x71, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52,
|
||||
0x04, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x10, 0x0a, 0x03, 0x72, 0x65, 0x71, 0x18, 0x02, 0x20, 0x01,
|
||||
0x28, 0x09, 0x52, 0x03, 0x72, 0x65, 0x71, 0x12, 0x12, 0x0a, 0x04, 0x61, 0x72, 0x67, 0x31, 0x18,
|
||||
0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x61, 0x72, 0x67, 0x31, 0x12, 0x12, 0x0a, 0x04, 0x61,
|
||||
0x72, 0x67, 0x32, 0x18, 0x04, 0x20, 0x01, 0x28, 0x04, 0x52, 0x04, 0x61, 0x72, 0x67, 0x32, 0x12,
|
||||
0x27, 0x0a, 0x06, 0x6e, 0x65, 0x73, 0x74, 0x65, 0x64, 0x18, 0x05, 0x20, 0x01, 0x28, 0x0b, 0x32,
|
||||
0x0f, 0x2e, 0x72, 0x65, 0x66, 0x6c, 0x65, 0x63, 0x74, 0x2e, 0x4e, 0x65, 0x73, 0x74, 0x65, 0x64,
|
||||
0x52, 0x06, 0x6e, 0x65, 0x73, 0x74, 0x65, 0x64, 0x22, 0x68, 0x0a, 0x06, 0x4e, 0x65, 0x73, 0x74,
|
||||
0x65, 0x64, 0x12, 0x1f, 0x0a, 0x0b, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x5f, 0x61, 0x72, 0x67,
|
||||
0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x09, 0x52, 0x0a, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x41,
|
||||
0x72, 0x67, 0x73, 0x12, 0x3d, 0x0a, 0x0b, 0x75, 0x69, 0x6e, 0x74, 0x36, 0x34, 0x5f, 0x61, 0x72,
|
||||
0x67, 0x73, 0x18, 0x02, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x1c, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c,
|
||||
0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x55, 0x49, 0x6e, 0x74, 0x36,
|
||||
0x34, 0x56, 0x61, 0x6c, 0x75, 0x65, 0x52, 0x0a, 0x75, 0x69, 0x6e, 0x74, 0x36, 0x34, 0x41, 0x72,
|
||||
0x67, 0x73, 0x42, 0x3b, 0x5a, 0x39, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d,
|
||||
0x2f, 0x75, 0x6e, 0x69, 0x73, 0x74, 0x61, 0x63, 0x6b, 0x2d, 0x6f, 0x72, 0x67, 0x2f, 0x6d, 0x69,
|
||||
0x63, 0x72, 0x6f, 0x2d, 0x74, 0x65, 0x73, 0x74, 0x73, 0x2f, 0x75, 0x74, 0x69, 0x6c, 0x2f, 0x72,
|
||||
0x65, 0x66, 0x6c, 0x65, 0x63, 0x74, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x3b, 0x70, 0x62, 0x62,
|
||||
0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
|
||||
}
|
||||
|
||||
var (
|
||||
file_test_proto_rawDescOnce sync.Once
|
||||
file_test_proto_rawDescData = file_test_proto_rawDesc
|
||||
)
|
||||
|
||||
func file_test_proto_rawDescGZIP() []byte {
|
||||
file_test_proto_rawDescOnce.Do(func() {
|
||||
file_test_proto_rawDescData = protoimpl.X.CompressGZIP(file_test_proto_rawDescData)
|
||||
})
|
||||
return file_test_proto_rawDescData
|
||||
}
|
||||
|
||||
var file_test_proto_msgTypes = make([]protoimpl.MessageInfo, 2)
|
||||
var file_test_proto_goTypes = []interface{}{
|
||||
(*CallReq)(nil), // 0: reflect.CallReq
|
||||
(*Nested)(nil), // 1: reflect.Nested
|
||||
(*wrapperspb.UInt64Value)(nil), // 2: google.protobuf.UInt64Value
|
||||
}
|
||||
var file_test_proto_depIdxs = []int32{
|
||||
1, // 0: reflect.CallReq.nested:type_name -> reflect.Nested
|
||||
2, // 1: reflect.Nested.uint64_args:type_name -> google.protobuf.UInt64Value
|
||||
2, // [2:2] is the sub-list for method output_type
|
||||
2, // [2:2] is the sub-list for method input_type
|
||||
2, // [2:2] is the sub-list for extension type_name
|
||||
2, // [2:2] is the sub-list for extension extendee
|
||||
0, // [0:2] is the sub-list for field type_name
|
||||
}
|
||||
|
||||
func init() { file_test_proto_init() }
|
||||
func file_test_proto_init() {
|
||||
if File_test_proto != nil {
|
||||
return
|
||||
}
|
||||
if !protoimpl.UnsafeEnabled {
|
||||
file_test_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} {
|
||||
switch v := v.(*CallReq); i {
|
||||
case 0:
|
||||
return &v.state
|
||||
case 1:
|
||||
return &v.sizeCache
|
||||
case 2:
|
||||
return &v.unknownFields
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
file_test_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} {
|
||||
switch v := v.(*Nested); i {
|
||||
case 0:
|
||||
return &v.state
|
||||
case 1:
|
||||
return &v.sizeCache
|
||||
case 2:
|
||||
return &v.unknownFields
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
}
|
||||
type x struct{}
|
||||
out := protoimpl.TypeBuilder{
|
||||
File: protoimpl.DescBuilder{
|
||||
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
|
||||
RawDescriptor: file_test_proto_rawDesc,
|
||||
NumEnums: 0,
|
||||
NumMessages: 2,
|
||||
NumExtensions: 0,
|
||||
NumServices: 0,
|
||||
},
|
||||
GoTypes: file_test_proto_goTypes,
|
||||
DependencyIndexes: file_test_proto_depIdxs,
|
||||
MessageInfos: file_test_proto_msgTypes,
|
||||
}.Build()
|
||||
File_test_proto = out.File
|
||||
file_test_proto_rawDesc = nil
|
||||
file_test_proto_goTypes = nil
|
||||
file_test_proto_depIdxs = nil
|
||||
}
|
19
util/reflect/proto/test.proto
Normal file
19
util/reflect/proto/test.proto
Normal file
@ -0,0 +1,19 @@
|
||||
syntax = "proto3";
|
||||
|
||||
package reflect;
|
||||
|
||||
option go_package = "github.com/unistack-org/micro-tests/util/reflect/proto;pb";
|
||||
import "google/protobuf/wrappers.proto";
|
||||
|
||||
message CallReq {
|
||||
string name = 1;
|
||||
string req = 2;
|
||||
string arg1 = 3;
|
||||
uint64 arg2 = 4;
|
||||
Nested nested = 5;
|
||||
};
|
||||
|
||||
message Nested {
|
||||
repeated string string_args = 1;
|
||||
repeated google.protobuf.UInt64Value uint64_args = 2;
|
||||
};
|
181
util/reflect/reflect_test.go
Normal file
181
util/reflect/reflect_test.go
Normal file
@ -0,0 +1,181 @@
|
||||
package reflect
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
pb "github.com/unistack-org/micro-tests/util/reflect/proto"
|
||||
rutil "github.com/unistack-org/micro/v3/util/reflect"
|
||||
)
|
||||
|
||||
func TestFieldName(t *testing.T) {
|
||||
name := rutil.FieldName("NestedArgs")
|
||||
if name != "nested_args" {
|
||||
t.Fatalf("%s != nested_args", name)
|
||||
}
|
||||
}
|
||||
|
||||
func TestMergeBool(t *testing.T) {
|
||||
type str struct {
|
||||
Bool bool `json:"bool"`
|
||||
}
|
||||
|
||||
mp := make(map[string]interface{})
|
||||
mp["bool"] = "true"
|
||||
s := &str{}
|
||||
|
||||
if err := rutil.Merge(s, mp, rutil.Tags([]string{"json"})); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if !s.Bool {
|
||||
t.Fatalf("merge bool error: %#+v\n", s)
|
||||
}
|
||||
|
||||
mp["bool"] = "false"
|
||||
|
||||
if err := rutil.Merge(s, mp, rutil.Tags([]string{"json"})); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if s.Bool {
|
||||
t.Fatalf("merge bool error: %#+v\n", s)
|
||||
}
|
||||
|
||||
mp["bool"] = 1
|
||||
|
||||
if err := rutil.Merge(s, mp, rutil.Tags([]string{"json"})); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if !s.Bool {
|
||||
t.Fatalf("merge bool error: %#+v\n", s)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func TestMergeString(t *testing.T) {
|
||||
type str struct {
|
||||
Bool string `json:"bool"`
|
||||
}
|
||||
|
||||
mp := make(map[string]interface{})
|
||||
mp["bool"] = true
|
||||
s := &str{}
|
||||
|
||||
if err := rutil.Merge(s, mp, rutil.Tags([]string{"json"})); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if s.Bool != "true" {
|
||||
t.Fatalf("merge bool error: %#+v\n", s)
|
||||
}
|
||||
|
||||
mp["bool"] = false
|
||||
|
||||
if err := rutil.Merge(s, mp, rutil.Tags([]string{"json"})); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if s.Bool != "false" {
|
||||
t.Fatalf("merge bool error: %#+v\n", s)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func TestMerge(t *testing.T) {
|
||||
dst := &pb.CallReq{
|
||||
Name: "name_old",
|
||||
Req: "req_old",
|
||||
}
|
||||
|
||||
mp := make(map[string]interface{})
|
||||
mp["name"] = "name_new"
|
||||
mp["req"] = "req_new"
|
||||
mp["arg2"] = 1
|
||||
mp["nested.string_args"] = []string{"args1", "args2"}
|
||||
mp["nested.uint64_args"] = []uint64{1, 2, 3}
|
||||
|
||||
mp = rutil.FlattenMap(mp)
|
||||
|
||||
if err := rutil.Merge(dst, mp, rutil.Tags([]string{"protobuf"})); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if dst.Name != "name_new" || dst.Req != "req_new" || dst.Arg2 != 1 {
|
||||
t.Fatalf("merge error: %#+v", dst)
|
||||
}
|
||||
|
||||
if dst.Nested == nil || len(dst.Nested.Uint64Args) != 3 ||
|
||||
len(dst.Nested.StringArgs) != 2 || dst.Nested.StringArgs[0] != "args1" ||
|
||||
len(dst.Nested.Uint64Args) != 3 || dst.Nested.Uint64Args[2].Value != 3 {
|
||||
t.Fatalf("merge error: %#+v", dst.Nested)
|
||||
}
|
||||
|
||||
nmp := make(map[string]interface{})
|
||||
nmp["nested.uint64_args"] = []uint64{4}
|
||||
nmp = rutil.FlattenMap(nmp)
|
||||
|
||||
if err := rutil.Merge(dst, nmp, rutil.SliceAppend(true), rutil.Tags([]string{"protobuf"})); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if dst.Nested == nil || len(dst.Nested.Uint64Args) != 4 || dst.Nested.Uint64Args[3].Value != 4 {
|
||||
t.Fatalf("merge error: %#+v", dst.Nested)
|
||||
}
|
||||
}
|
||||
|
||||
func TestMergeNested(t *testing.T) {
|
||||
type CallReqNested struct {
|
||||
StringArgs []string `json:"string_args"`
|
||||
Uint64Args []uint64 `json:"uint64_args"`
|
||||
Nested *CallReqNested `json:"nested2"`
|
||||
}
|
||||
|
||||
type CallReq struct {
|
||||
Name string `json:"name"`
|
||||
Req string `json:"req"`
|
||||
Arg2 int `json:"arg2"`
|
||||
Nested *CallReqNested `json:"nested"`
|
||||
}
|
||||
|
||||
dst := &CallReq{
|
||||
Name: "name_old",
|
||||
Req: "req_old",
|
||||
}
|
||||
|
||||
mp := make(map[string]interface{})
|
||||
mp["name"] = "name_new"
|
||||
mp["req"] = "req_new"
|
||||
mp["arg2"] = 1
|
||||
mp["nested.string_args"] = []string{"args1", "args2"}
|
||||
mp["nested.uint64_args"] = []uint64{1, 2, 3}
|
||||
mp["nested.nested2.uint64_args"] = []uint64{1, 2, 3}
|
||||
|
||||
mp = rutil.FlattenMap(mp)
|
||||
|
||||
if err := rutil.Merge(dst, mp, rutil.Tags([]string{"json"})); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if dst.Name != "name_new" || dst.Req != "req_new" || dst.Arg2 != 1 {
|
||||
t.Fatalf("merge error: %#+v", dst)
|
||||
}
|
||||
|
||||
if dst.Nested == nil || len(dst.Nested.Uint64Args) != 3 ||
|
||||
len(dst.Nested.StringArgs) != 2 || dst.Nested.StringArgs[0] != "args1" ||
|
||||
len(dst.Nested.Uint64Args) != 3 || dst.Nested.Uint64Args[2] != 3 {
|
||||
t.Fatalf("merge error: %#+v", dst.Nested)
|
||||
}
|
||||
|
||||
nmp := make(map[string]interface{})
|
||||
nmp["nested.uint64_args"] = []uint64{4}
|
||||
nmp = rutil.FlattenMap(nmp)
|
||||
|
||||
if err := rutil.Merge(dst, nmp, rutil.SliceAppend(true), rutil.Tags([]string{"json"})); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if dst.Nested == nil || len(dst.Nested.Uint64Args) != 4 || dst.Nested.Uint64Args[3] != 4 {
|
||||
t.Fatalf("merge error: %#+v", dst.Nested)
|
||||
}
|
||||
}
|
@ -87,12 +87,12 @@ func TestPrometheusMetrics(t *testing.T) {
|
||||
}
|
||||
defer s.Stop()
|
||||
|
||||
req := c.NewRequest(name, "Test.Method", &TestRequest{IsError: false}, client.WithContentType("application/json"))
|
||||
req := c.NewRequest(name, "Test.Method", &TestRequest{IsError: false}, client.RequestContentType("application/json"))
|
||||
rsp := TestResponse{}
|
||||
|
||||
assert.NoError(t, c.Call(context.TODO(), req, &rsp))
|
||||
|
||||
req = c.NewRequest(name, "Test.Method", &TestRequest{IsError: true}, client.WithContentType("application/json"))
|
||||
req = c.NewRequest(name, "Test.Method", &TestRequest{IsError: true}, client.RequestContentType("application/json"))
|
||||
assert.Error(t, c.Call(context.TODO(), req, &rsp))
|
||||
|
||||
list, _ := prometheus.DefaultGatherer.Gather()
|
||||
|
@ -117,7 +117,7 @@ func TestClient(t *testing.T) {
|
||||
ctx, span, err := otwrapper.StartSpanFromOutgoingContext(context.Background(), tracer, "root")
|
||||
assert.NoError(err)
|
||||
|
||||
req := c.NewRequest(serverName, "Test.Method", &TestRequest{IsError: tt.isError}, client.WithContentType("application/json"))
|
||||
req := c.NewRequest(serverName, "Test.Method", &TestRequest{IsError: tt.isError}, client.RequestContentType("application/json"))
|
||||
rsp := TestResponse{}
|
||||
err = c.Call(ctx, req, &rsp)
|
||||
if tt.isError {
|
||||
|
Loading…
Reference in New Issue
Block a user