Skip to content
Snippets Groups Projects
Commit 0df1704f authored by vito.he's avatar vito.he
Browse files

Fix:bug about mergeUrl

parent 19f25318
No related branches found
No related tags found
No related merge requests found
......@@ -232,7 +232,13 @@ func (dir *registryDirectory) Destroy() {
func mergeUrl(serviceUrl common.URL, referenceUrl *common.URL) common.URL {
mergedUrl := serviceUrl
var methodConfigMergeFcn = []func(method string){}
//iterator the referenceUrl if serviceUrl not have the key ,merge in
for k, v := range referenceUrl.Params {
if _, ok := mergedUrl.Params[k]; !ok {
mergedUrl.Params.Set(k, v[0])
}
}
//loadBalance strategy config
if v := referenceUrl.Params.Get(constant.LOADBALANCE_KEY); v != "" {
mergedUrl.Params.Set(constant.LOADBALANCE_KEY, v)
......
......@@ -127,3 +127,19 @@ func normalRegistryDir() (*registryDirectory, *registry.MockRegistry) {
}
return registryDirectory, mockRegistry.(*registry.MockRegistry)
}
func TestMergeUrl(t *testing.T) {
referenceUrlParams := url.Values{}
referenceUrlParams.Set(constant.CLUSTER_KEY, "random")
referenceUrlParams.Set("test3", "1")
serviceUrlParams := url.Values{}
serviceUrlParams.Set("test2", "1")
serviceUrlParams.Set(constant.CLUSTER_KEY, "roundrobin")
referenceUrl, _ := common.NewURL(context.TODO(), "mock1://127.0.0.1:1111", common.WithParams(referenceUrlParams))
serviceUrl, _ := common.NewURL(context.TODO(), "mock2://127.0.0.1:20000", common.WithParams(serviceUrlParams))
mergedUrl := mergeUrl(serviceUrl, &referenceUrl)
assert.Equal(t, "random", mergedUrl.GetParam(constant.CLUSTER_KEY, ""))
assert.Equal(t, "1", mergedUrl.GetParam("test2", ""))
assert.Equal(t, "1", mergedUrl.GetParam("test3", ""))
}
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment