Skip to content
Snippets Groups Projects
Commit e7418dcc authored by cvictory's avatar cvictory
Browse files

add unit test and keep origin SetParams method

parent 0c5e318a
No related branches found
No related tags found
No related merge requests found
......@@ -432,7 +432,7 @@ func (c *URL) SetParam(key string, value string) {
// 1. if there already has same key, the value will be override
// 2. it's not thread safe
// usually it should only be invoked when you want to modify an url, such as MergeURL
func (c *URL) SetParams(param url.Values) {
func (c *URL) ReplaceParams(param url.Values) {
c.paramsLock.Lock()
defer c.paramsLock.Unlock()
c.params = param
......@@ -570,15 +570,15 @@ func (c *URL) GetMethodParamBool(method string, key string, d bool) bool {
return r
}
// SetParams will put all key-value pair into url.
// 1. if there already has same key, the value will be override
// 2. it's not thread safe
// 3. think twice when you want to invoke this method
//func (c *URL) SetParams(m url.Values) {
// for k := range m {
// c.SetParam(k, m.Get(k))
// }
//}
//SetParams will put all key-value pair into url.
//1. if there already has same key, the value will be override
//2. it's not thread safe
//3. think twice when you want to invoke this method
func (c *URL) SetParams(m url.Values) {
for k := range m {
c.SetParam(k, m.Get(k))
}
}
// ToMap transfer URL to Map
func (c *URL) ToMap() map[string]string {
......@@ -659,7 +659,7 @@ func MergeUrl(serviceUrl *URL, referenceUrl *URL) *URL {
}
}
// In this way, we will raise some performance.
mergedUrl.SetParams(params)
mergedUrl.ReplaceParams(params)
return mergedUrl
}
......
......@@ -307,6 +307,16 @@ func TestURLSetParams(t *testing.T) {
assert.Equal(t, "2.6.0", u1.GetParam("version", ""))
}
func TestURLReplaceParams(t *testing.T) {
u1, err := NewURL("dubbo://127.0.0.1:20000/com.ikurento.user.UserProvider?interface=com.ikurento.user.UserProvider&group=&version=2.6.0&configVersion=1.0")
assert.NoError(t, err)
params := url.Values{}
params.Set("key", "3")
u1.ReplaceParams(params)
assert.Equal(t, "3", u1.GetParam("key", ""))
assert.Equal(t, "", u1.GetParam("version", ""))
}
func TestClone(t *testing.T) {
u1, err := NewURL("dubbo://127.0.0.1:20000/com.ikurento.user.UserProvider?interface=com.ikurento.user.UserProvider&group=&version=2.6.0&configVersion=1.0")
assert.NoError(t, err)
......
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