Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

运行单元测试时 GetService 只能返回IP不能返回正确的端口 #744

Open
yangyile1990 opened this issue Apr 10, 2024 · 2 comments

Comments

@yangyile1990
Copy link

What version of nacos-sdk-go are you using?

github.com/nacos-group/nacos-sdk-go/v2 v2.2.5

What version of nacos-sever are you using?

docker run --name nacos-quick -e MODE=standalone -p 8848:8848 -p 9848:9848 -d nacos/nacos-server:v2.2.0

What version of Go are you using (go version)?

go version go1.22.2 darwin/arm64

What operating system (Linux, Windows, …) and version?

mac

What did you do?

If possible, provide a recipe for reproducing the error.
code is:

service, err := client.GetService(vo.GetServiceParam{
	ServiceName: config.GlobalConfig.ApplicationName,
})

for _, host := range service.Hosts {
	var port = host.Port
	if port == 0 {
		return errors.New("port is zero")
	}
}

operation is: use the GoLand run testcase:
截屏2024-04-10 17 16 10

What did you expect to see?

port == 8080

What did you see instead?

port == 0

#743

@yangyile1990
Copy link
Author

yangyile1990 commented Apr 10, 2024

假如使用
go test -run TestNacosRoute_Online

go test -run TestNacosRoute_Offline
就万事大吉。

假如使用GoLand右键run test case 就会出错。

serverConfig := constant.NewServerConfig(ip, port)

clientConfig := constant.NewClientConfig(
    constant.WithEndpoint(endpoint),
    constant.WithNamespaceId(Namespace),
    constant.WithAppName(AppName),
)

client, err := clients.CreateNamingClient(map[string]interface{}{
    "serverConfigs": []constant.ServerConfig{*serverConfig},
    "clientConfig":  clientConfig,
})

service, err := client.GetService(vo.GetServiceParam{
	ServiceName: config.GlobalConfig.ApplicationName,
})

for _, host := range service.Hosts {
	var port = host.Port
	if port == 0 {
		return errors.New("port is zero")
	}
}

跟以前的 #743 是完全一样的,这导致我运行测试时非常不方便,你们可以下载最新的GoLand 或者前一个版本的GoLand,都是类似的问题。

@binbin0325
Copy link
Member

可以提供能复现的完整代码,包括注册实例的逻辑和获取实例

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants