diff --git a/protocol/dubbo/client_test.go b/protocol/dubbo/client_test.go index 744ffa80d6..8b0ba169b8 100644 --- a/protocol/dubbo/client_test.go +++ b/protocol/dubbo/client_test.go @@ -37,7 +37,13 @@ import ( "github.com/apache/dubbo-go/protocol" ) -func TestClient_CallOneway(t *testing.T) { +const ( + mockMethodNameGetUser = "GetUser" + mockMethodNameGetBigPkg = "GetBigPkg" + mockAddress = "127.0.0.1:20000" +) + +func TestClientCallOneway(t *testing.T) { proto, url := InitTest(t) c := &Client{ @@ -50,15 +56,14 @@ func TestClient_CallOneway(t *testing.T) { } c.pool = newGettyRPCClientConnPool(c, clientConf.PoolSize, time.Duration(int(time.Second)*clientConf.PoolTTL)) - //user := &User{} - err := c.CallOneway(NewRequest("127.0.0.1:20000", url, "GetUser", []interface{}{"1", "username"}, nil)) + err := c.CallOneway(NewRequest(mockAddress, url, mockMethodNameGetUser, []interface{}{"1", "username"}, nil)) assert.NoError(t, err) // destroy proto.Destroy() } -func TestClient_Call(t *testing.T) { +func TestClientCall(t *testing.T) { proto, url := InitTest(t) c := &Client{ @@ -77,50 +82,50 @@ func TestClient_Call(t *testing.T) { ) user = &User{} - err = c.Call(NewRequest("127.0.0.1:20000", url, "GetBigPkg", []interface{}{nil}, nil), NewResponse(user, nil)) + err = c.Call(NewRequest(mockAddress, url, mockMethodNameGetBigPkg, []interface{}{nil}, nil), NewResponse(user, nil)) assert.NoError(t, err) assert.NotEqual(t, "", user.Id) assert.NotEqual(t, "", user.Name) user = &User{} - err = c.Call(NewRequest("127.0.0.1:20000", url, "GetUser", []interface{}{"1", "username"}, nil), NewResponse(user, nil)) + err = c.Call(NewRequest(mockAddress, url, mockMethodNameGetUser, []interface{}{"1", "username"}, nil), NewResponse(user, nil)) assert.NoError(t, err) assert.Equal(t, User{Id: "1", Name: "username"}, *user) user = &User{} - err = c.Call(NewRequest("127.0.0.1:20000", url, "GetUser0", []interface{}{"1", nil, "username"}, nil), NewResponse(user, nil)) + err = c.Call(NewRequest(mockAddress, url, "GetUser0", []interface{}{"1", nil, "username"}, nil), NewResponse(user, nil)) assert.NoError(t, err) assert.Equal(t, User{Id: "1", Name: "username"}, *user) - err = c.Call(NewRequest("127.0.0.1:20000", url, "GetUser1", []interface{}{}, nil), NewResponse(user, nil)) + err = c.Call(NewRequest(mockAddress, url, "GetUser1", []interface{}{}, nil), NewResponse(user, nil)) assert.NoError(t, err) - err = c.Call(NewRequest("127.0.0.1:20000", url, "GetUser2", []interface{}{}, nil), NewResponse(user, nil)) + err = c.Call(NewRequest(mockAddress, url, "GetUser2", []interface{}{}, nil), NewResponse(user, nil)) assert.EqualError(t, err, "error") user2 := []interface{}{} - err = c.Call(NewRequest("127.0.0.1:20000", url, "GetUser3", []interface{}{}, nil), NewResponse(&user2, nil)) + err = c.Call(NewRequest(mockAddress, url, "GetUser3", []interface{}{}, nil), NewResponse(&user2, nil)) assert.NoError(t, err) assert.Equal(t, &User{Id: "1", Name: "username"}, user2[0]) user2 = []interface{}{} - err = c.Call(NewRequest("127.0.0.1:20000", url, "GetUser4", []interface{}{[]interface{}{"1", "username"}}, nil), NewResponse(&user2, nil)) + err = c.Call(NewRequest(mockAddress, url, "GetUser4", []interface{}{[]interface{}{"1", "username"}}, nil), NewResponse(&user2, nil)) assert.NoError(t, err) assert.Equal(t, &User{Id: "1", Name: "username"}, user2[0]) user3 := map[interface{}]interface{}{} - err = c.Call(NewRequest("127.0.0.1:20000", url, "GetUser5", []interface{}{map[interface{}]interface{}{"id": "1", "name": "username"}}, nil), NewResponse(&user3, nil)) + err = c.Call(NewRequest(mockAddress, url, "GetUser5", []interface{}{map[interface{}]interface{}{"id": "1", "name": "username"}}, nil), NewResponse(&user3, nil)) assert.NoError(t, err) assert.NotNil(t, user3) assert.Equal(t, &User{Id: "1", Name: "username"}, user3["key"]) user = &User{} - err = c.Call(NewRequest("127.0.0.1:20000", url, "GetUser6", []interface{}{0}, nil), NewResponse(user, nil)) + err = c.Call(NewRequest(mockAddress, url, "GetUser6", []interface{}{0}, nil), NewResponse(user, nil)) assert.NoError(t, err) assert.Equal(t, User{Id: "", Name: ""}, *user) user = &User{} - err = c.Call(NewRequest("127.0.0.1:20000", url, "GetUser6", []interface{}{1}, nil), NewResponse(user, nil)) + err = c.Call(NewRequest(mockAddress, url, "GetUser6", []interface{}{1}, nil), NewResponse(user, nil)) assert.NoError(t, err) assert.Equal(t, User{Id: "1", Name: ""}, *user) @@ -128,7 +133,7 @@ func TestClient_Call(t *testing.T) { proto.Destroy() } -func TestClient_AsyncCall(t *testing.T) { +func TestClientAsyncCall(t *testing.T) { proto, url := InitTest(t) c := &Client{ @@ -144,7 +149,7 @@ func TestClient_AsyncCall(t *testing.T) { user := &User{} lock := sync.Mutex{} lock.Lock() - err := c.AsyncCall(NewRequest("127.0.0.1:20000", url, "GetUser", []interface{}{"1", "username"}, nil), func(response common.CallbackResponse) { + err := c.AsyncCall(NewRequest(mockAddress, url, mockMethodNameGetUser, []interface{}{"1", "username"}, nil), func(response common.CallbackResponse) { r := response.(AsyncCallbackResponse) assert.Equal(t, User{Id: "1", Name: "username"}, *r.Reply.(*Response).reply.(*User)) lock.Unlock() diff --git a/protocol/dubbo/codec_test.go b/protocol/dubbo/codec_test.go index 5dc71f0d08..c2ca443637 100644 --- a/protocol/dubbo/codec_test.go +++ b/protocol/dubbo/codec_test.go @@ -29,7 +29,7 @@ import ( "github.com/stretchr/testify/assert" ) -func TestDubboPackage_MarshalAndUnmarshal(t *testing.T) { +func TestDubboPackageMarshalAndUnmarshal(t *testing.T) { pkg := &DubboPackage{} pkg.Body = []interface{}{"a"} pkg.Header.Type = hessian.PackageHeartbeat diff --git a/protocol/dubbo/dubbo_invoker_test.go b/protocol/dubbo/dubbo_invoker_test.go index 1a64301f82..c0640d5558 100644 --- a/protocol/dubbo/dubbo_invoker_test.go +++ b/protocol/dubbo/dubbo_invoker_test.go @@ -35,7 +35,7 @@ import ( "github.com/apache/dubbo-go/protocol/invocation" ) -func TestDubboInvoker_Invoke(t *testing.T) { +func TestDubboInvokerInvoke(t *testing.T) { proto, url := InitTest(t) c := &Client{ @@ -51,7 +51,7 @@ func TestDubboInvoker_Invoke(t *testing.T) { invoker := NewDubboInvoker(url, c) user := &User{} - inv := invocation.NewRPCInvocationWithOptions(invocation.WithMethodName("GetUser"), invocation.WithArguments([]interface{}{"1", "username"}), + inv := invocation.NewRPCInvocationWithOptions(invocation.WithMethodName(mockMethodNameGetUser), invocation.WithArguments([]interface{}{"1", "username"}), invocation.WithReply(user), invocation.WithAttachments(map[string]string{"test_key": "test_value"})) // Call diff --git a/protocol/dubbo/dubbo_protocol_test.go b/protocol/dubbo/dubbo_protocol_test.go index 14f6868ad4..6f3892be67 100644 --- a/protocol/dubbo/dubbo_protocol_test.go +++ b/protocol/dubbo/dubbo_protocol_test.go @@ -31,15 +31,19 @@ import ( "github.com/apache/dubbo-go/protocol" ) -func TestDubboProtocol_Export(t *testing.T) { - // Export - proto := GetProtocol() - srvConf = &ServerConfig{} - url, err := common.NewURL("dubbo://127.0.0.1:20000/com.ikurento.user.UserProvider?anyhost=true&" + +const ( + mockCommonUrl = "dubbo://127.0.0.1:20000/com.ikurento.user.UserProvider?anyhost=true&" + "application=BDTService&category=providers&default.timeout=10000&dubbo=dubbo-provider-golang-1.0.0&" + "environment=dev&interface=com.ikurento.user.UserProvider&ip=192.168.56.1&methods=GetUser%2C&" + "module=dubbogo+user-info+server&org=ikurento.com&owner=ZX&pid=1447&revision=0.0.1&" + - "side=provider&timeout=3000×tamp=1556509797245") + "side=provider&timeout=3000×tamp=1556509797245" +) + +func TestDubboProtocolExport(t *testing.T) { + // Export + proto := GetProtocol() + srvConf = &ServerConfig{} + url, err := common.NewURL(mockCommonUrl) assert.NoError(t, err) exporter := proto.Export(protocol.NewBaseInvoker(url)) @@ -48,11 +52,7 @@ func TestDubboProtocol_Export(t *testing.T) { assert.True(t, eq) // second service: the same path and the different version - url2, err := common.NewURL("dubbo://127.0.0.1:20000/com.ikurento.user.UserProvider?anyhost=true&"+ - "application=BDTService&category=providers&default.timeout=10000&dubbo=dubbo-provider-golang-1.0.0&"+ - "environment=dev&interface=com.ikurento.user.UserProvider&ip=192.168.56.1&methods=GetUser%2C&"+ - "module=dubbogo+user-info+server&org=ikurento.com&owner=ZX&pid=1447&revision=0.0.1&"+ - "side=provider&timeout=3000×tamp=1556509797245", common.WithParamsValue(constant.VERSION_KEY, "v1.1")) + url2, err := common.NewURL(mockCommonUrl, common.WithParamsValue(constant.VERSION_KEY, "v1.1")) assert.NoError(t, err) exporter2 := proto.Export(protocol.NewBaseInvoker(url2)) // make sure url @@ -74,14 +74,10 @@ func TestDubboProtocol_Export(t *testing.T) { assert.False(t, ok) } -func TestDubboProtocol_Refer(t *testing.T) { +func TestDubboProtocolRefer(t *testing.T) { // Refer proto := GetProtocol() - url, err := common.NewURL("dubbo://127.0.0.1:20000/com.ikurento.user.UserProvider?anyhost=true&" + - "application=BDTService&category=providers&default.timeout=10000&dubbo=dubbo-provider-golang-1.0.0&" + - "environment=dev&interface=com.ikurento.user.UserProvider&ip=192.168.56.1&methods=GetUser%2C&" + - "module=dubbogo+user-info+server&org=ikurento.com&owner=ZX&pid=1447&revision=0.0.1&" + - "side=provider&timeout=3000×tamp=1556509797245") + url, err := common.NewURL(mockCommonUrl) assert.NoError(t, err) clientConf = &ClientConfig{} invoker := proto.Refer(url) diff --git a/protocol/grpc/common_test.go b/protocol/grpc/common_test.go index 33c2fc617d..b732283a9b 100644 --- a/protocol/grpc/common_test.go +++ b/protocol/grpc/common_test.go @@ -106,7 +106,7 @@ func dubboGreeterSayHelloHandler(srv interface{}, ctx context.Context, Server: srv, FullMethod: "/helloworld.Greeter/SayHello", } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { + handler := func(context.Context, interface{}) (interface{}, error) { result := base.GetProxyImpl().Invoke(context.Background(), invo) return result.Result(), result.Error() } diff --git a/protocol/grpc/grpc_invoker_test.go b/protocol/grpc/grpc_invoker_test.go index 3054ada133..d5ebbb4f47 100644 --- a/protocol/grpc/grpc_invoker_test.go +++ b/protocol/grpc/grpc_invoker_test.go @@ -33,11 +33,19 @@ import ( "github.com/apache/dubbo-go/protocol/invocation" ) +const ( + mockGrpcCommonUrl = "grpc://127.0.0.1:30000/GrpcGreeterImpl?accesslog=&anyhost=true&app.version=0.0.1&application=BDTService&async=false&bean.name=GrpcGreeterImpl" + + "&category=providers&cluster=failover&dubbo=dubbo-provider-golang-2.6.0&environment=dev&execute.limit=&execute.limit.rejected.handler=&generic=false&group=&interface=io.grpc.examples.helloworld.GreeterGrpc%24IGreeter" + + "&ip=192.168.1.106&loadbalance=random&methods.SayHello.loadbalance=random&methods.SayHello.retries=1&methods.SayHello.tps.limit.interval=&methods.SayHello.tps.limit.rate=&methods.SayHello.tps.limit.strategy=" + + "&methods.SayHello.weight=0&module=dubbogo+say-hello+client&name=BDTService&organization=ikurento.com&owner=ZX&pid=49427&reference.filter=cshutdown®istry.role=3&remote.timestamp=1576923717&retries=" + + "&service.filter=echo%2Ctoken%2Caccesslog%2Ctps%2Cexecute%2Cpshutdown&side=provider×tamp=1576923740&tps.limit.interval=&tps.limit.rate=&tps.limit.rejected.handler=&tps.limit.strategy=&tps.limiter=&version=&warmup=100!" +) + func TestInvoke(t *testing.T) { go internal.InitGrpcServer() defer internal.ShutdownGrpcServer() - url, err := common.NewURL("grpc://127.0.0.1:30000/GrpcGreeterImpl?accesslog=&anyhost=true&app.version=0.0.1&application=BDTService&async=false&bean.name=GrpcGreeterImpl&category=providers&cluster=failover&dubbo=dubbo-provider-golang-2.6.0&environment=dev&execute.limit=&execute.limit.rejected.handler=&generic=false&group=&interface=io.grpc.examples.helloworld.GreeterGrpc%24IGreeter&ip=192.168.1.106&loadbalance=random&methods.SayHello.loadbalance=random&methods.SayHello.retries=1&methods.SayHello.tps.limit.interval=&methods.SayHello.tps.limit.rate=&methods.SayHello.tps.limit.strategy=&methods.SayHello.weight=0&module=dubbogo+say-hello+client&name=BDTService&organization=ikurento.com&owner=ZX&pid=49427&reference.filter=cshutdown®istry.role=3&remote.timestamp=1576923717&retries=&service.filter=echo%2Ctoken%2Caccesslog%2Ctps%2Cexecute%2Cpshutdown&side=provider×tamp=1576923740&tps.limit.interval=&tps.limit.rate=&tps.limit.rejected.handler=&tps.limit.strategy=&tps.limiter=&version=&warmup=100!") + url, err := common.NewURL(mockGrpcCommonUrl) assert.Nil(t, err) cli := NewClient(url) diff --git a/protocol/grpc/grpc_protocol_test.go b/protocol/grpc/grpc_protocol_test.go index d028f8ef42..87ce714fc7 100644 --- a/protocol/grpc/grpc_protocol_test.go +++ b/protocol/grpc/grpc_protocol_test.go @@ -32,12 +32,12 @@ import ( "github.com/apache/dubbo-go/protocol/grpc/internal" ) -func TestGrpcProtocol_Export(t *testing.T) { +func TestGrpcProtocolExport(t *testing.T) { // Export addService() proto := GetProtocol() - url, err := common.NewURL("grpc://127.0.0.1:40000/GrpcGreeterImpl?accesslog=&app.version=0.0.1&application=BDTService&bean.name=GrpcGreeterImpl&cluster=failover&environment=dev&execute.limit=&execute.limit.rejected.handler=&group=&interface=io.grpc.examples.helloworld.GreeterGrpc%24IGreeter&loadbalance=random&methods.SayHello.loadbalance=random&methods.SayHello.retries=1&methods.SayHello.tps.limit.interval=&methods.SayHello.tps.limit.rate=&methods.SayHello.tps.limit.strategy=&methods.SayHello.weight=0&module=dubbogo+say-hello+client&name=BDTService&organization=ikurento.com&owner=ZX®istry.role=3&retries=&service.filter=echo%2Ctoken%2Caccesslog%2Ctps%2Cexecute%2Cpshutdown×tamp=1576923717&tps.limit.interval=&tps.limit.rate=&tps.limit.rejected.handler=&tps.limit.strategy=&tps.limiter=&version=&warmup=100") + url, err := common.NewURL(mockGrpcCommonUrl) assert.NoError(t, err) exporter := proto.Export(protocol.NewBaseInvoker(url)) time.Sleep(time.Second) @@ -61,13 +61,13 @@ func TestGrpcProtocol_Export(t *testing.T) { assert.False(t, ok) } -func TestGrpcProtocol_Refer(t *testing.T) { +func TestGrpcProtocolRefer(t *testing.T) { go internal.InitGrpcServer() defer internal.ShutdownGrpcServer() time.Sleep(time.Second) proto := GetProtocol() - url, err := common.NewURL("grpc://127.0.0.1:30000/GrpcGreeterImpl?accesslog=&anyhost=true&app.version=0.0.1&application=BDTService&async=false&bean.name=GrpcGreeterImpl&category=providers&cluster=failover&dubbo=dubbo-provider-golang-2.6.0&environment=dev&execute.limit=&execute.limit.rejected.handler=&generic=false&group=&interface=io.grpc.examples.helloworld.GreeterGrpc%24IGreeter&ip=192.168.1.106&loadbalance=random&methods.SayHello.loadbalance=random&methods.SayHello.retries=1&methods.SayHello.tps.limit.interval=&methods.SayHello.tps.limit.rate=&methods.SayHello.tps.limit.strategy=&methods.SayHello.weight=0&module=dubbogo+say-hello+client&name=BDTService&organization=ikurento.com&owner=ZX&pid=49427&reference.filter=cshutdown®istry.role=3&remote.timestamp=1576923717&retries=&service.filter=echo%2Ctoken%2Caccesslog%2Ctps%2Cexecute%2Cpshutdown&side=provider×tamp=1576923740&tps.limit.interval=&tps.limit.rate=&tps.limit.rejected.handler=&tps.limit.strategy=&tps.limiter=&version=&warmup=100!") + url, err := common.NewURL(mockGrpcCommonUrl) assert.NoError(t, err) invoker := proto.Refer(url) diff --git a/protocol/jsonrpc/http_test.go b/protocol/jsonrpc/http_test.go index f8480bf32e..576591940d 100644 --- a/protocol/jsonrpc/http_test.go +++ b/protocol/jsonrpc/http_test.go @@ -48,7 +48,15 @@ type ( } ) -func TestHTTPClient_Call(t *testing.T) { +const ( + mockJsonCommonUrl = "jsonrpc://127.0.0.1:20001/UserProvider?anyhost=true&" + + "application=BDTService&category=providers&default.timeout=10000&dubbo=dubbo-provider-golang-1.0.0&" + + "environment=dev&interface=com.ikurento.user.UserProvider&ip=192.168.56.1&methods=GetUser%2C&" + + "module=dubbogo+user-info+server&org=ikurento.com&owner=ZX&pid=1447&revision=0.0.1&" + + "side=provider&timeout=3000×tamp=1556509797245&bean.name=UserProvider" +) + +func TestHTTPClientCall(t *testing.T) { methods, err := common.ServiceMap.Register("com.ikurento.user.UserProvider", "jsonrpc", &UserProvider{}) assert.NoError(t, err) @@ -56,11 +64,7 @@ func TestHTTPClient_Call(t *testing.T) { // Export proto := GetProtocol() - url, err := common.NewURL("jsonrpc://127.0.0.1:20001/UserProvider?anyhost=true&" + - "application=BDTService&category=providers&default.timeout=10000&dubbo=dubbo-provider-golang-1.0.0&" + - "environment=dev&interface=com.ikurento.user.UserProvider&ip=192.168.56.1&methods=GetUser%2C&" + - "module=dubbogo+user-info+server&org=ikurento.com&owner=ZX&pid=1447&revision=0.0.1&" + - "side=provider&timeout=3000×tamp=1556509797245&bean.name=UserProvider") + url, err := common.NewURL(mockJsonCommonUrl) assert.NoError(t, err) proto.Export(&proxy_factory.ProxyInvoker{ BaseInvoker: *protocol.NewBaseInvoker(url), diff --git a/protocol/jsonrpc/json.go b/protocol/jsonrpc/json.go index 389ead9c1a..7b05a22943 100644 --- a/protocol/jsonrpc/json.go +++ b/protocol/jsonrpc/json.go @@ -124,10 +124,8 @@ func (c *jsonClientCodec) Write(d *CodecData) ([]byte, error) { if param != nil { switch k := reflect.TypeOf(param).Kind(); k { case reflect.Map: - if reflect.TypeOf(param).Key().Kind() == reflect.String { - if reflect.ValueOf(param).IsNil() { - param = nil - } + if reflect.TypeOf(param).Key().Kind() == reflect.String && reflect.ValueOf(param).IsNil() { + param = nil } case reflect.Slice: if reflect.ValueOf(param).IsNil() { @@ -137,10 +135,8 @@ func (c *jsonClientCodec) Write(d *CodecData) ([]byte, error) { case reflect.Ptr: switch ptrK := reflect.TypeOf(param).Elem().Kind(); ptrK { case reflect.Map: - if reflect.TypeOf(param).Elem().Key().Kind() == reflect.String { - if reflect.ValueOf(param).Elem().IsNil() { - param = nil - } + if reflect.TypeOf(param).Elem().Key().Kind() == reflect.String && reflect.ValueOf(param).Elem().IsNil() { + param = nil } case reflect.Slice: if reflect.ValueOf(param).Elem().IsNil() { diff --git a/protocol/jsonrpc/json_test.go b/protocol/jsonrpc/json_test.go index ade7424612..a3814e9ad5 100644 --- a/protocol/jsonrpc/json_test.go +++ b/protocol/jsonrpc/json_test.go @@ -30,7 +30,7 @@ type TestData struct { Test string } -func TestJsonClientCodec_Write(t *testing.T) { +func TestJsonClientCodecWrite(t *testing.T) { cd := &CodecData{ ID: 1, Method: "GetUser", @@ -46,7 +46,7 @@ func TestJsonClientCodec_Write(t *testing.T) { assert.EqualError(t, err, "unsupported param type: int") } -func TestJsonClientCodec_Read(t *testing.T) { +func TestJsonClientCodecRead(t *testing.T) { codec := newJsonClientCodec() codec.pending[1] = "GetUser" rsp := &TestData{} @@ -60,7 +60,7 @@ func TestJsonClientCodec_Read(t *testing.T) { assert.EqualError(t, err, "{\"code\":-32000,\"message\":\"error\"}") } -func TestServerCodec_Write(t *testing.T) { +func TestServerCodecWrite(t *testing.T) { codec := newServerCodec() a := json.RawMessage([]byte("1")) codec.req = serverRequest{Version: "1.0", Method: "GetUser", ID: &a} @@ -73,7 +73,7 @@ func TestServerCodec_Write(t *testing.T) { assert.Equal(t, "{\"jsonrpc\":\"2.0\",\"id\":1,\"result\":{\"Test\":\"test\"},\"error\":{\"code\":-32000,\"message\":\"error\"}}\n", string(data)) } -func TestServerCodec_Read(t *testing.T) { +func TestServerCodecRead(t *testing.T) { codec := newServerCodec() header := map[string]string{} err := codec.ReadHeader(header, []byte("{\"jsonrpc\":\"2.0\",\"method\":\"GetUser\",\"params\":[\"args\",2],\"id\":1}\n")) diff --git a/protocol/jsonrpc/jsonrpc_invoker_test.go b/protocol/jsonrpc/jsonrpc_invoker_test.go index 0f14ba11e2..d7124ca07c 100644 --- a/protocol/jsonrpc/jsonrpc_invoker_test.go +++ b/protocol/jsonrpc/jsonrpc_invoker_test.go @@ -34,7 +34,7 @@ import ( "github.com/apache/dubbo-go/protocol/invocation" ) -func TestJsonrpcInvoker_Invoke(t *testing.T) { +func TestJsonrpcInvokerInvoke(t *testing.T) { methods, err := common.ServiceMap.Register("UserProvider", "jsonrpc", &UserProvider{}) assert.NoError(t, err) diff --git a/protocol/jsonrpc/jsonrpc_protocol_test.go b/protocol/jsonrpc/jsonrpc_protocol_test.go index c00bed12fe..10a9016913 100644 --- a/protocol/jsonrpc/jsonrpc_protocol_test.go +++ b/protocol/jsonrpc/jsonrpc_protocol_test.go @@ -34,7 +34,7 @@ import ( "github.com/apache/dubbo-go/protocol" ) -func TestJsonrpcProtocol_Export(t *testing.T) { +func TestJsonrpcProtocolExport(t *testing.T) { // Export proto := GetProtocol() url, err := common.NewURL("jsonrpc://127.0.0.1:20000/com.ikurento.user.UserProvider?anyhost=true&" + @@ -65,7 +65,7 @@ func TestJsonrpcProtocol_Export(t *testing.T) { assert.False(t, ok) } -func TestJsonrpcProtocol_Refer(t *testing.T) { +func TestJsonrpcProtocolRefer(t *testing.T) { // Refer proto := GetProtocol() url, err := common.NewURL("jsonrpc://127.0.0.1:20000/com.ikurento.user.UserProvider?anyhost=true&" + diff --git a/protocol/protocolwrapper/mock_protocol_filter.go b/protocol/protocolwrapper/mock_protocol_filter.go index 8763c20410..2e9ffed06f 100644 --- a/protocol/protocolwrapper/mock_protocol_filter.go +++ b/protocol/protocolwrapper/mock_protocol_filter.go @@ -45,5 +45,5 @@ func (pfw *mockProtocolFilter) Refer(url common.URL) protocol.Invoker { // Destroy will do nothing func (pfw *mockProtocolFilter) Destroy() { - + return } diff --git a/protocol/protocolwrapper/protocol_filter_wrapper_test.go b/protocol/protocolwrapper/protocol_filter_wrapper_test.go index 8491d57462..b03ea7b9b6 100644 --- a/protocol/protocolwrapper/protocol_filter_wrapper_test.go +++ b/protocol/protocolwrapper/protocol_filter_wrapper_test.go @@ -36,7 +36,7 @@ import ( "github.com/apache/dubbo-go/protocol" ) -func TestProtocolFilterWrapper_Export(t *testing.T) { +func TestProtocolFilterWrapperExport(t *testing.T) { filtProto := extension.GetProtocol(FILTER) filtProto.(*ProtocolFilterWrapper).protocol = &protocol.BaseProtocol{} @@ -48,7 +48,7 @@ func TestProtocolFilterWrapper_Export(t *testing.T) { assert.True(t, ok) } -func TestProtocolFilterWrapper_Refer(t *testing.T) { +func TestProtocolFilterWrapperRefer(t *testing.T) { filtProto := extension.GetProtocol(FILTER) filtProto.(*ProtocolFilterWrapper).protocol = &protocol.BaseProtocol{} diff --git a/protocol/rest/client/client_impl/resty_client.go b/protocol/rest/client/client_impl/resty_client.go index b60f50a5a7..f301d94504 100644 --- a/protocol/rest/client/client_impl/resty_client.go +++ b/protocol/rest/client/client_impl/resty_client.go @@ -50,7 +50,7 @@ func NewRestyClient(restOption *client.RestOptions) client.RestClient { client := resty.New() client.SetTransport( &http.Transport{ - DialContext: func(ctx context.Context, network, addr string) (net.Conn, error) { + DialContext: func(_ context.Context, network, addr string) (net.Conn, error) { c, err := net.DialTimeout(network, addr, restOption.ConnectTimeout) if err != nil { return nil, err diff --git a/protocol/rest/config/reader/rest_config_reader_test.go b/protocol/rest/config/reader/rest_config_reader_test.go index d2dba40b9b..c6f891262c 100644 --- a/protocol/rest/config/reader/rest_config_reader_test.go +++ b/protocol/rest/config/reader/rest_config_reader_test.go @@ -31,7 +31,7 @@ import ( "github.com/apache/dubbo-go/protocol/rest/config" ) -func TestRestConfigReader_ReadConsumerConfig(t *testing.T) { +func TestRestConfigReaderReadConsumerConfig(t *testing.T) { bs, err := yaml.LoadYMLConfig("./testdata/consumer_config.yml") assert.NoError(t, err) configReader := NewRestConfigReader() @@ -40,7 +40,7 @@ func TestRestConfigReader_ReadConsumerConfig(t *testing.T) { assert.NotEmpty(t, config.GetRestConsumerServiceConfigMap()) } -func TestRestConfigReader_ReadProviderConfig(t *testing.T) { +func TestRestConfigReaderReadProviderConfig(t *testing.T) { bs, err := yaml.LoadYMLConfig("./testdata/provider_config.yml") assert.NoError(t, err) configReader := NewRestConfigReader() diff --git a/protocol/rest/rest_invoker_test.go b/protocol/rest/rest_invoker_test.go index 2ea260c58d..9df97a211e 100644 --- a/protocol/rest/rest_invoker_test.go +++ b/protocol/rest/rest_invoker_test.go @@ -39,7 +39,15 @@ import ( "github.com/apache/dubbo-go/protocol/rest/server/server_impl" ) -func TestRestInvoker_Invoke(t *testing.T) { +const ( + mockRestCommonUrl = "rest://127.0.0.1:8877/com.ikurento.user.UserProvider?anyhost=true&" + + "application=BDTService&category=providers&default.timeout=10000&dubbo=dubbo-provider-golang-1.0.0&" + + "environment=dev&interface=com.ikurento.user.UserProvider&ip=192.168.56.1&methods=GetUser%2C&" + + "module=dubbogo+user-info+server&org=ikurento.com&owner=ZX&pid=1447&revision=0.0.1&" + + "side=provider&timeout=3000×tamp=1556509797245" +) + +func TestRestInvokerInvoke(t *testing.T) { // Refer proto := GetRestProtocol() defer proto.Destroy() @@ -55,11 +63,7 @@ func TestRestInvoker_Invoke(t *testing.T) { chain.ProcessFilter(request, response) }) - url, err := common.NewURL("rest://127.0.0.1:8877/com.ikurento.user.UserProvider?anyhost=true&" + - "application=BDTService&category=providers&default.timeout=10000&dubbo=dubbo-provider-golang-1.0.0&" + - "environment=dev&interface=com.ikurento.user.UserProvider&ip=192.168.56.1&methods=GetUser%2C&" + - "module=dubbogo+user-info+server&org=ikurento.com&owner=ZX&pid=1447&revision=0.0.1&" + - "side=provider&timeout=3000×tamp=1556509797245") + url, err := common.NewURL(mockRestCommonUrl) assert.NoError(t, err) _, err = common.ServiceMap.Register("UserProvider", url.Protocol, &UserProvider{}) assert.NoError(t, err) diff --git a/protocol/rest/rest_protocol_test.go b/protocol/rest/rest_protocol_test.go index 9117148777..9ff4e7df7f 100644 --- a/protocol/rest/rest_protocol_test.go +++ b/protocol/rest/rest_protocol_test.go @@ -38,14 +38,10 @@ import ( rest_config "github.com/apache/dubbo-go/protocol/rest/config" ) -func TestRestProtocol_Refer(t *testing.T) { +func TestRestProtocolRefer(t *testing.T) { // Refer proto := GetRestProtocol() - url, err := common.NewURL("rest://127.0.0.1:20000/com.ikurento.user.UserProvider?anyhost=true&" + - "application=BDTService&category=providers&default.timeout=10000&dubbo=dubbo-provider-golang-1.0.0&" + - "environment=dev&interface=com.ikurento.user.UserProvider&ip=192.168.56.1&methods=GetUser%2C&" + - "module=dubbogo+user-info+server&org=ikurento.com&owner=ZX&pid=1447&revision=0.0.1&" + - "side=provider&timeout=3000×tamp=1556509797245") + url, err := common.NewURL(mockRestCommonUrl) assert.NoError(t, err) con := config.ConsumerConfig{ ConnectTimeout: 5 * time.Second, @@ -71,14 +67,10 @@ func TestRestProtocol_Refer(t *testing.T) { assert.Equal(t, 0, invokersLen) } -func TestRestProtocol_Export(t *testing.T) { +func TestRestProtocolExport(t *testing.T) { // Export proto := GetRestProtocol() - url, err := common.NewURL("rest://127.0.0.1:8888/com.ikurento.user.UserProvider?anyhost=true&" + - "application=BDTService&category=providers&default.timeout=10000&dubbo=dubbo-provider-golang-1.0.0&" + - "environment=dev&interface=com.ikurento.user.UserProvider&ip=192.168.56.1&methods=GetUser%2C&" + - "module=dubbogo+user-info+server&org=ikurento.com&owner=ZX&pid=1447&revision=0.0.1&" + - "side=provider&timeout=3000×tamp=1556509797245") + url, err := common.NewURL(mockRestCommonUrl) assert.NoError(t, err) _, err = common.ServiceMap.Register("UserProvider", url.Protocol, &UserProvider{}) assert.NoError(t, err) diff --git a/protocol/rpc_status.go b/protocol/rpc_status.go index 0eeca6c1bb..60becfb341 100644 --- a/protocol/rpc_status.go +++ b/protocol/rpc_status.go @@ -170,12 +170,12 @@ func CurrentTimeMillis() int64 { // Destroy is used to clean all status func CleanAllStatus() { - delete1 := func(key interface{}, value interface{}) bool { + delete1 := func(key, _ interface{}) bool { methodStatistics.Delete(key) return true } methodStatistics.Range(delete1) - delete2 := func(key interface{}, value interface{}) bool { + delete2 := func(key, _ interface{}) bool { serviceStatistic.Delete(key) return true } diff --git a/protocol/rpc_status_test.go b/protocol/rpc_status_test.go index 611b7cba6e..cc12753cf2 100644 --- a/protocol/rpc_status_test.go +++ b/protocol/rpc_status_test.go @@ -30,10 +30,14 @@ import ( "github.com/apache/dubbo-go/common" ) +const ( + mockCommonDubboUrl = "dubbo://192.168.10.10:20000/com.ikurento.user.UserProvider" +) + func TestBeginCount(t *testing.T) { defer CleanAllStatus() - url, _ := common.NewURL("dubbo://192.168.10.10:20000/com.ikurento.user.UserProvider") + url, _ := common.NewURL(mockCommonDubboUrl) BeginCount(url, "test") urlStatus := GetURLStatus(url) methodStatus := GetMethodStatus(url, "test") @@ -47,7 +51,7 @@ func TestBeginCount(t *testing.T) { func TestEndCount(t *testing.T) { defer CleanAllStatus() - url, _ := common.NewURL("dubbo://192.168.10.10:20000/com.ikurento.user.UserProvider") + url, _ := common.NewURL(mockCommonDubboUrl) EndCount(url, "test", 100, true) urlStatus := GetURLStatus(url) methodStatus := GetMethodStatus(url, "test") @@ -60,7 +64,7 @@ func TestEndCount(t *testing.T) { func TestGetMethodStatus(t *testing.T) { defer CleanAllStatus() - url, _ := common.NewURL("dubbo://192.168.10.10:20000/com.ikurento.user.UserProvider") + url, _ := common.NewURL(mockCommonDubboUrl) status := GetMethodStatus(url, "test") assert.NotNil(t, status) assert.Equal(t, int32(0), status.total) @@ -69,25 +73,25 @@ func TestGetMethodStatus(t *testing.T) { func TestGetUrlStatus(t *testing.T) { defer CleanAllStatus() - url, _ := common.NewURL("dubbo://192.168.10.10:20000/com.ikurento.user.UserProvider") + url, _ := common.NewURL(mockCommonDubboUrl) status := GetURLStatus(url) assert.NotNil(t, status) assert.Equal(t, int32(0), status.total) } -func Test_beginCount0(t *testing.T) { +func TestbeginCount0(t *testing.T) { defer CleanAllStatus() - url, _ := common.NewURL("dubbo://192.168.10.10:20000/com.ikurento.user.UserProvider") + url, _ := common.NewURL(mockCommonDubboUrl) status := GetURLStatus(url) beginCount0(status) assert.Equal(t, int32(1), status.active) } -func Test_All(t *testing.T) { +func TestAll(t *testing.T) { defer CleanAllStatus() - url, _ := common.NewURL("dubbo://192.168.10.10:20000/com.ikurento.user.UserProvider") + url, _ := common.NewURL(mockCommonDubboUrl) request(url, "test", 100, false, true) urlStatus := GetURLStatus(url) methodStatus := GetMethodStatus(url, "test")