This is an automated email from the ASF dual-hosted git repository.

alexstocks pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/dubbo-go.git


The following commit(s) were added to refs/heads/develop by this push:
     new 35ea88642 refactor: remove config package dependency from remoting 
tests (#3198)
35ea88642 is described below

commit 35ea886421f97d881bb73e8ddf110233a1a2fa9a
Author: 翎 <[email protected]>
AuthorDate: Tue Feb 10 09:57:53 2026 +0800

    refactor: remove config package dependency from remoting tests (#3198)
---
 remoting/getty/getty_client.go      |   3 +
 remoting/getty/getty_client_test.go |  21 -----
 remoting/getty/getty_server_test.go |  22 ------
 remoting/nacos/builder.go           |  12 ++-
 remoting/nacos/builder_test.go      | 151 +++++++++++++++++++++++-------------
 5 files changed, 108 insertions(+), 101 deletions(-)

diff --git a/remoting/getty/getty_client.go b/remoting/getty/getty_client.go
index bbbe743ff..a2dc071f8 100644
--- a/remoting/getty/getty_client.go
+++ b/remoting/getty/getty_client.go
@@ -244,6 +244,9 @@ func (c *Client) Close() {
 
 // Request send request
 func (c *Client) Request(request *remoting.Request, timeout time.Duration, 
response *remoting.PendingResponse) error {
+       if timeout <= 0 {
+               timeout = c.opts.RequestTimeout
+       }
        _, session, err := c.selectSession(c.addr)
        if err != nil {
                return perrors.WithStack(err)
diff --git a/remoting/getty/getty_client_test.go 
b/remoting/getty/getty_client_test.go
index 1b1d3fd28..9af9fc777 100644
--- a/remoting/getty/getty_client_test.go
+++ b/remoting/getty/getty_client_test.go
@@ -38,7 +38,6 @@ import (
 import (
        "dubbo.apache.org/dubbo-go/v3/common"
        "dubbo.apache.org/dubbo-go/v3/common/constant"
-       "dubbo.apache.org/dubbo-go/v3/config"
        "dubbo.apache.org/dubbo-go/v3/global"
        "dubbo.apache.org/dubbo-go/v3/protocol/base"
        "dubbo.apache.org/dubbo-go/v3/protocol/invocation"
@@ -273,26 +272,6 @@ func (u User) JavaClassName() string {
        return "com.ikurento.user.User"
 }
 
-// TODO: Temporary compatibility with old APIs, can be removed later
-func TestInitClientOldApi(t *testing.T) {
-       originRootConf := config.GetRootConfig()
-       rootConf := config.RootConfig{
-               Protocols: map[string]*config.ProtocolConfig{
-                       "dubbo": {
-                               Name: "dubbo",
-                               Ip:   "127.0.0.1",
-                               Port: "20003",
-                       },
-               },
-       }
-       config.SetRootConfig(rootConf)
-       url, err := common.NewURL("dubbo://127.0.0.1:20003/test")
-       require.NoError(t, err)
-       initClient(url)
-       config.SetRootConfig(*originRootConf)
-       assert.NotNil(t, srvConf)
-}
-
 func TestInitClient(t *testing.T) {
        url, err := common.NewURL("dubbo://127.0.0.1:20003/test")
        require.NoError(t, err)
diff --git a/remoting/getty/getty_server_test.go 
b/remoting/getty/getty_server_test.go
index 4f7121a54..a2966d1d1 100644
--- a/remoting/getty/getty_server_test.go
+++ b/remoting/getty/getty_server_test.go
@@ -22,37 +22,15 @@ import (
 )
 
 import (
-       "github.com/stretchr/testify/assert"
        "github.com/stretchr/testify/require"
 )
 
 import (
        "dubbo.apache.org/dubbo-go/v3/common"
        "dubbo.apache.org/dubbo-go/v3/common/constant"
-       "dubbo.apache.org/dubbo-go/v3/config"
        "dubbo.apache.org/dubbo-go/v3/global"
 )
 
-// TODO: Temporary compatibility with old APIs, can be removed later
-func TestInitServerOldApi(t *testing.T) {
-       originRootConf := config.GetRootConfig()
-       rootConf := config.RootConfig{
-               Protocols: map[string]*config.ProtocolConfig{
-                       "dubbo": {
-                               Name: "dubbo",
-                               Ip:   "127.0.0.1",
-                               Port: "20003",
-                       },
-               },
-       }
-       config.SetRootConfig(rootConf)
-       url, err := common.NewURL("dubbo://127.0.0.1:20003/test")
-       require.NoError(t, err)
-       initServer(url)
-       config.SetRootConfig(*originRootConf)
-       assert.NotNil(t, srvConf)
-}
-
 func TestInitServer(t *testing.T) {
        url, err := common.NewURL("dubbo://127.0.0.1:20003/test")
        require.NoError(t, err)
diff --git a/remoting/nacos/builder.go b/remoting/nacos/builder.go
index 20807112d..a29b86bab 100644
--- a/remoting/nacos/builder.go
+++ b/remoting/nacos/builder.go
@@ -38,6 +38,11 @@ import (
        "dubbo.apache.org/dubbo-go/v3/common/constant"
 )
 
+var (
+       newNacosNamingClient = nacosClient.NewNacosNamingClient
+       newNacosConfigClient = nacosClient.NewNacosConfigClient
+)
+
 // NewNacosConfigClientByUrl read the config from url and build an instance
 func NewNacosConfigClientByUrl(url *common.URL) 
(*nacosClient.NacosConfigClient, error) {
        sc, cc, err := GetNacosConfig(url)
@@ -48,7 +53,7 @@ func NewNacosConfigClientByUrl(url *common.URL) 
(*nacosClient.NacosConfigClient,
        if len(clientName) <= 0 {
                return nil, perrors.New("nacos client name must set")
        }
-       return nacosClient.NewNacosConfigClient(clientName, true, sc, cc)
+       return newNacosConfigClient(clientName, true, sc, cc)
 }
 
 // GetNacosConfig will return the nacos config
@@ -83,6 +88,9 @@ func GetNacosConfig(url *common.URL) 
([]nacosConstant.ServerConfig, nacosConstan
                        if len(portContextPath) > 1 {
                                contextPath = constant.PathSeparator + 
strings.Join(portContextPath[1:], constant.PathSeparator)
                        }
+                       if contextPath == "" && len(url.Path) > 0 {
+                               contextPath = url.Path
+                       }
                        serverConfigs = append(serverConfigs, 
nacosConstant.ServerConfig{IpAddr: ip, Port: uint64(port), ContextPath: 
contextPath})
                }
        }
@@ -126,5 +134,5 @@ func NewNacosClientByURL(url *common.URL) 
(*nacosClient.NacosNamingClient, error
        if len(namespaceID) > 0 {
                clientName += namespaceID
        }
-       return nacosClient.NewNacosNamingClient(clientName, true, scs, cc)
+       return newNacosNamingClient(clientName, true, scs, cc)
 }
diff --git a/remoting/nacos/builder_test.go b/remoting/nacos/builder_test.go
index 54e058fd9..03702401f 100644
--- a/remoting/nacos/builder_test.go
+++ b/remoting/nacos/builder_test.go
@@ -17,7 +17,6 @@
 
 package nacos
 
-/*
 import (
        "net/url"
        "reflect"
@@ -25,11 +24,9 @@ import (
 )
 
 import (
-       "github.com/agiledragon/gomonkey"
-
        nacosClient "github.com/dubbogo/gost/database/kv/nacos"
 
-       nacosConstant "github.com/nacos-group/nacos-sdk-go/v2common/constant"
+       nacosConstant "github.com/nacos-group/nacos-sdk-go/v2/common/constant"
 
        "github.com/stretchr/testify/assert"
 )
@@ -37,7 +34,6 @@ import (
 import (
        "dubbo.apache.org/dubbo-go/v3/common"
        "dubbo.apache.org/dubbo-go/v3/common/constant"
-       "dubbo.apache.org/dubbo-go/v3/config"
 )
 
 func getRegURL() *common.URL {
@@ -53,16 +49,17 @@ func getRegURL() *common.URL {
 
 type args struct {
        url *common.URL
-       rc  *config.RemoteConfig
 }
 
 func TestNewNacosClientByURL(t *testing.T) {
-       patches := gomonkey.NewPatches()
-       patches = patches.ApplyFunc(nacosClient.NewNacosNamingClient, func(name 
string, share bool, sc []nacosConstant.ServerConfig,
+       oldNewNacosNamingClient := newNacosNamingClient
+       newNacosNamingClient = func(name string, share bool, sc 
[]nacosConstant.ServerConfig,
                cc nacosConstant.ClientConfig) (*nacosClient.NacosNamingClient, 
error) {
                return &nacosClient.NacosNamingClient{}, nil
+       }
+       t.Cleanup(func() {
+               newNacosNamingClient = oldNewNacosNamingClient
        })
-       defer patches.Reset()
 
        tests := []struct {
                name    string
@@ -93,47 +90,14 @@ func TestNewNacosClientByURL(t *testing.T) {
        }
 }
 
-func TestNewNacosClient(t *testing.T) {
-       patches := gomonkey.NewPatches()
-       patches = patches.ApplyFunc(nacosClient.NewNacosNamingClient, func(name 
string, share bool, sc []nacosConstant.ServerConfig,
-               cc nacosConstant.ClientConfig) (*nacosClient.NacosNamingClient, 
error) {
-               return &nacosClient.NacosNamingClient{}, nil
-       })
-       defer patches.Reset()
+func TestNewNacosClientByURLMissingClientName(t *testing.T) {
+       regURLMap := url.Values{}
+       regURLMap.Set(constant.NacosNamespaceID, "nacos")
+       regURL, _ := common.NewURL("registry://test.nacos.io:80", 
common.WithParams(regURLMap))
 
-       tests := []struct {
-               name    string
-               args    args
-               want    *nacosClient.NacosNamingClient
-               wantErr bool
-       }{
-               {
-                       name: "test",
-                       args: args{
-                               rc: &config.RemoteConfig{
-                                       Address:  "test.nacos.io:80/nacos",
-                                       Protocol: "nacos",
-                                       Timeout:  "10s",
-                                       Username: "naocs",
-                                       Password: "nacos",
-                               },
-                       },
-                       want:    &nacosClient.NacosNamingClient{},
-                       wantErr: false,
-               },
-       }
-       for _, tt := range tests {
-               t.Run(tt.name, func(t *testing.T) {
-                       got, err := NewNacosClient(tt.args.rc)
-                       if (err != nil) != tt.wantErr {
-                               t.Errorf("NewNacosClient() error = %v, wantErr 
%v", err, tt.wantErr)
-                               return
-                       }
-                       if !reflect.DeepEqual(got, tt.want) {
-                               t.Errorf("NewNacosClient() got = %v, want %v", 
got, tt.want)
-                       }
-               })
-       }
+       client, err := NewNacosClientByURL(regURL)
+       assert.Nil(t, client)
+       assert.Error(t, err)
 }
 
 func TestGetNacosConfig(t *testing.T) {
@@ -157,6 +121,69 @@ func TestGetNacosConfig(t *testing.T) {
                        },
                        wantErr: false,
                },
+               {
+                       name: "with_context_path",
+                       args: args{
+                               url: func() *common.URL {
+                                       regURLMap := url.Values{}
+                                       regURLMap.Set(constant.ClientNameKey, 
"nacos-client")
+                                       regURL, _ := 
common.NewURL("registry://test.nacos.io:80/nacos", common.WithParams(regURLMap))
+                                       return regURL
+                               }(),
+                       },
+                       want: []nacosConstant.ServerConfig{
+                               {
+                                       IpAddr:      "test.nacos.io",
+                                       Port:        80,
+                                       ContextPath: "/nacos",
+                               },
+                       },
+                       wantErr: false,
+               },
+               {
+                       name: "endpoint_only",
+                       args: args{
+                               url: func() *common.URL {
+                                       regURLMap := url.Values{}
+                                       regURLMap.Set(constant.NacosEndpoint, 
"acm.aliyun.com")
+                                       regURLMap.Set(constant.ClientNameKey, 
"nacos-client")
+                                       regURL, _ := 
common.NewURL("registry://test.nacos.io:80", common.WithParams(regURLMap))
+                                       return regURL
+                               }(),
+                       },
+                       want:    nil,
+                       wantErr: false,
+               },
+               {
+                       name: "nil_url",
+                       args: args{
+                               url: nil,
+                       },
+                       want:    []nacosConstant.ServerConfig{},
+                       wantErr: true,
+               },
+               {
+                       name: "empty_location",
+                       args: args{
+                               url: func() *common.URL {
+                                       regURL, _ := 
common.NewURL("registry://", common.WithParams(url.Values{}))
+                                       return regURL
+                               }(),
+                       },
+                       want:    []nacosConstant.ServerConfig{},
+                       wantErr: true,
+               },
+               {
+                       name: "bad_address",
+                       args: args{
+                               url: func() *common.URL {
+                                       regURL, _ := 
common.NewURL("registry://bad-address", common.WithParams(url.Values{}))
+                                       return regURL
+                               }(),
+                       },
+                       want:    []nacosConstant.ServerConfig{},
+                       wantErr: true,
+               },
        }
        for _, tt := range tests {
                t.Run(tt.name, func(t *testing.T) {
@@ -168,18 +195,22 @@ func TestGetNacosConfig(t *testing.T) {
                        if !reflect.DeepEqual(got, tt.want) {
                                t.Errorf("GetNacosConfig() got = %v, want %v", 
got, tt.want)
                        }
-                       assert.NotNil(t, got1)
+                       if !tt.wantErr {
+                               assert.NotNil(t, got1)
+                       }
                })
        }
 }
 
 func TestNewNacosConfigClientByUrl(t *testing.T) {
-       patches := gomonkey.NewPatches()
-       patches = patches.ApplyFunc(nacosClient.NewNacosNamingClient, func(name 
string, share bool, sc []nacosConstant.ServerConfig,
-               cc nacosConstant.ClientConfig) (*nacosClient.NacosNamingClient, 
error) {
-               return &nacosClient.NacosNamingClient{}, nil
+       oldNewNacosConfigClient := newNacosConfigClient
+       newNacosConfigClient = func(name string, share bool, sc 
[]nacosConstant.ServerConfig,
+               cc nacosConstant.ClientConfig) (*nacosClient.NacosConfigClient, 
error) {
+               return &nacosClient.NacosConfigClient{}, nil
+       }
+       t.Cleanup(func() {
+               newNacosConfigClient = oldNewNacosConfigClient
        })
-       defer patches.Reset()
 
        tests := []struct {
                name    string
@@ -207,4 +238,12 @@ func TestNewNacosConfigClientByUrl(t *testing.T) {
        }
 }
 
-*/
+func TestNewNacosConfigClientByUrlMissingClientName(t *testing.T) {
+       regURLMap := url.Values{}
+       regURLMap.Set(constant.NacosNamespaceID, "nacos")
+       regURL, _ := common.NewURL("registry://test.nacos.io:80", 
common.WithParams(regURLMap))
+
+       client, err := NewNacosConfigClientByUrl(regURL)
+       assert.Nil(t, client)
+       assert.Error(t, err)
+}

Reply via email to