dubbo.apache.org/dubbo-go/v3@v3.1.1/config_center/configurator/override_test.go (about) 1 /* 2 * Licensed to the Apache Software Foundation (ASF) under one or more 3 * contributor license agreements. See the NOTICE file distributed with 4 * this work for additional information regarding copyright ownership. 5 * The ASF licenses this file to You under the Apache License, Version 2.0 6 * (the "License"); you may not use this file except in compliance with 7 * the License. You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 */ 17 18 package configurator 19 20 import ( 21 "testing" 22 ) 23 24 import ( 25 "github.com/stretchr/testify/assert" 26 ) 27 28 import ( 29 "dubbo.apache.org/dubbo-go/v3/common" 30 "dubbo.apache.org/dubbo-go/v3/common/constant" 31 "dubbo.apache.org/dubbo-go/v3/common/extension" 32 ) 33 34 const ( 35 defaults = "default" 36 override = "override" 37 failfast = "failfast" 38 failover = "failover" 39 ) 40 41 func TestConfigureVersion2p6(t *testing.T) { 42 url, err := common.NewURL("override://0.0.0.0:0/com.xxx.mock.userProvider?group=1&version=1&cluster=failfast&application=BDTService") 43 assert.NoError(t, err) 44 configurator := extension.GetConfigurator(defaults, url) 45 assert.Equal(t, override, configurator.GetUrl().Protocol) 46 47 providerUrl, err := common.NewURL("jsonrpc://127.0.0.1:20001/com.ikurento.user.UserProvider?anyhost=true&app.version=0.0.1&application=BDTService&category=providers&cluster=failover&dubbo=dubbo-provider-golang-2.6.0&environment=dev&group=&interface=com.ikurento.user.UserProvider&ip=10.32.20.124&loadbalance=random&methods.GetUser.loadbalance=random&methods.GetUser.retries=1&methods.GetUser.weight=0&module=dubbogo+user-info+server&name=BDTService&organization=ikurento.com&owner=ZX&pid=64225&retries=0&service.filter=echo&side=provider×tamp=1562076628&version=&warmup=100") 48 assert.NoError(t, err) 49 configurator.Configure(providerUrl) 50 assert.Equal(t, failfast, providerUrl.GetParam(constant.ClusterKey, "")) 51 } 52 53 func TestConfigureVersionOverrideAddr(t *testing.T) { 54 url, err := common.NewURL("override://0.0.0.0:0/com.xxx.mock.userProvider?group=1&version=1&cluster=failfast&application=BDTService&providerAddresses=127.0.0.2:20001|127.0.0.3:20001") 55 assert.NoError(t, err) 56 configurator := extension.GetConfigurator(defaults, url) 57 assert.Equal(t, override, configurator.GetUrl().Protocol) 58 59 providerUrl, err := common.NewURL("jsonrpc://127.0.0.1:20001/com.ikurento.user.UserProvider?anyhost=true&app.version=0.0.1&application=BDTService&category=providers&cluster=failover&dubbo=dubbo-provider-golang-2.6.0&environment=dev&group=&interface=com.ikurento.user.UserProvider&ip=10.32.20.124&loadbalance=random&methods.GetUser.loadbalance=random&methods.GetUser.retries=1&methods.GetUser.weight=0&module=dubbogo+user-info+server&name=BDTService&organization=ikurento.com&owner=ZX&pid=64225&retries=0&service.filter=echo&side=provider×tamp=1562076628&version=&warmup=100") 60 assert.NoError(t, err) 61 configurator.Configure(providerUrl) 62 assert.Equal(t, failover, providerUrl.GetParam(constant.ClusterKey, "")) 63 } 64 65 func TestConfigureVersion2p6WithIp(t *testing.T) { 66 url, err := common.NewURL("override://127.0.0.1:20001/com.xxx.mock.userProvider?group=1&version=1&cluster=failfast&application=BDTService") 67 assert.NoError(t, err) 68 configurator := extension.GetConfigurator(defaults, url) 69 assert.Equal(t, override, configurator.GetUrl().Protocol) 70 71 providerUrl, err := common.NewURL("jsonrpc://127.0.0.1:20001/com.ikurento.user.UserProvider?anyhost=true&app.version=0.0.1&application=BDTService&category=providers&cluster=failover&dubbo=dubbo-provider-golang-2.6.0&environment=dev&group=&interface=com.ikurento.user.UserProvider&ip=10.32.20.124&loadbalance=random&methods.GetUser.loadbalance=random&methods.GetUser.retries=1&methods.GetUser.weight=0&module=dubbogo+user-info+server&name=BDTService&organization=ikurento.com&owner=ZX&pid=64225&retries=0&service.filter=echo&side=provider×tamp=1562076628&version=&warmup=100") 72 assert.NoError(t, err) 73 configurator.Configure(providerUrl) 74 assert.Equal(t, failfast, providerUrl.GetParam(constant.ClusterKey, "")) 75 } 76 77 func TestConfigureVersion2p7(t *testing.T) { 78 url, err := common.NewURL("jsonrpc://0.0.0.0:20001/com.xxx.mock.userProvider?group=1&version=1&cluster=failfast&application=BDTService&configVersion=1.0&side=provider") 79 assert.NoError(t, err) 80 configurator := extension.GetConfigurator(defaults, url) 81 82 providerUrl, err := common.NewURL("jsonrpc://127.0.0.1:20001/com.ikurento.user.UserProvider?anyhost=true&app.version=0.0.1&application=BDTService&category=providers&cluster=failover&dubbo=dubbo-provider-golang-2.6.0&environment=dev&group=&interface=com.ikurento.user.UserProvider&ip=10.32.20.124&loadbalance=random&methods.GetUser.loadbalance=random&methods.GetUser.retries=1&methods.GetUser.weight=0&module=dubbogo+user-info+server&name=BDTService&organization=ikurento.com&owner=ZX&pid=64225&retries=0&service.filter=echo&side=provider×tamp=1562076628&version=&warmup=100") 83 assert.NoError(t, err) 84 configurator.Configure(providerUrl) 85 assert.Equal(t, failfast, providerUrl.GetParam(constant.ClusterKey, "")) 86 }