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

The NamespaceId is configured incorrectly, but the operation can also succeed #10

Closed
mahuaibo opened this issue Jul 2, 2019 · 1 comment

Comments

@mahuaibo
Copy link

mahuaibo commented Jul 2, 2019

There seems to be no filter limit

         "clientConfig": constant.ClientConfig{
			//NamespaceId:          "bf8ab528-e832-4ebc-ab94-dd7ec7c0e843", -- right
			NamespaceId:          "marx", // wrong
			...
		},

         success, err := client.PublishConfig(vo.ConfigParam{
		DataId:  "com.hello",
		Group:   "marx",
		Content: "hello world2",
	})
	
	fmt.Println(success, err)

	content, err := client.GetConfig(vo.ConfigParam{
		DataId: "com.hello",
		Group:  "marx"})

	fmt.Println(content, err)

out:
2019/07/02 11:41:54 [INFO] logDir:<data/nacos/log> cacheDir:</private/var/folders/w4/d_d_m03523j12lnn4ypdq90m0000gp/T/cache>
true
hello world2

@binbin0325
Copy link
Member

binbin0325 commented Jul 8, 2020

@mahuaibo Check the client you built. GetConfig will return an error if the namespace is different.
Refer to the following test.
//Alibaba Nacos config center

package nacos

import (
	"fmt"
	"github.com/nacos-group/nacos-sdk-go/clients/config_client"
	"github.com/nacos-group/nacos-sdk-go/clients/nacos_client"
	"github.com/nacos-group/nacos-sdk-go/common/constant"
	"github.com/nacos-group/nacos-sdk-go/common/http_agent"
	"github.com/nacos-group/nacos-sdk-go/vo"
	"github.com/stretchr/testify/assert"
	"testing"
)
var serverConfigTest = constant.ServerConfig{
	ContextPath: "/nacos",
	Port:        80,
	IpAddr:      "console.nacos.io",
}
var clientConfigTest = constant.ClientConfig{
	TimeoutMs:      10000,
	ListenInterval: 20000,
	BeatInterval:   10000,
}

func cretateConfigClientTest() config_client.ConfigClient {
	nc := nacos_client.NacosClient{}
	nc.SetServerConfig([]constant.ServerConfig{serverConfigTest})
	nc.SetClientConfig(clientConfigTest)
	nc.SetHttpAgent(&http_agent.HttpAgent{})
	client, _ := config_client.NewConfigClient(&nc)
	return client
}

func TestNacosGetConfigByNamespaceErr(t *testing.T){
	clientConfigTest.NamespaceId="test1"
	configClient := cretateConfigClientTest()
	content, err := configClient.GetConfig(vo.ConfigParam{
		DataId: "test_data",
		Group:  "test_group",
	})
	assert.True(t, content == "" && err != nil, "NacosDataSource get config failed.")
}

func TestNacosGetConfigByNamespace(t *testing.T){
	clientConfigTest.NamespaceId="test1"
	configClient := cretateConfigClientTest()
	published, err := configClient.PublishConfig(vo.ConfigParam{
		DataId: "test_data",
		Group:  "test_group",
		Content: "xxxxx",
	})
	assert.True(t, published && err == nil, "NacosDataSource get config failed.")
	content, err := configClient.GetConfig(vo.ConfigParam{
		DataId: "test_data",
		Group:  "test_group",
	})
	fmt.Println(content)
	assert.True(t, content != "" && err == nil, "NacosDataSource get config sucess.")
}

@lzp0412 lzp0412 closed this as completed Jul 24, 2020
binbin0325 added a commit that referenced this issue Oct 12, 2020
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

3 participants