From 241d9b14c2e706fe47538a0ad34ee1fe10e3773b Mon Sep 17 00:00:00 2001 From: Joe Zou <yixian.zou@gmail.com> Date: Wed, 26 Feb 2020 22:03:55 +0800 Subject: [PATCH] add UT for app_router --- cluster/router/chain/chain_test.go | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/cluster/router/chain/chain_test.go b/cluster/router/chain/chain_test.go index 2343fc80d..2864b35c2 100644 --- a/cluster/router/chain/chain_test.go +++ b/cluster/router/chain/chain_test.go @@ -91,9 +91,30 @@ func TestNewRouterChainURLNil(t *testing.T) { } func TestRouterChain_AddRouters(t *testing.T) { + ts, z, _, err := zookeeper.NewMockZookeeperClient("test", 15*time.Second) + assert.NoError(t, err) + err = z.Create("/dubbo/config/dubbo/test-condition.condition-router") + assert.NoError(t, err) + + testyml := `enabled: true +force: true +runtime: false +conditions: + - => host != 172.22.3.91 +` + + _, err = z.Conn.Set("/dubbo/config/dubbo/test-condition.condition-router", []byte(testyml), 0) + assert.NoError(t, err) + defer ts.Stop() + defer z.Close() + + zkUrl, _ := common.NewURL("zookeeper://127.0.0.1:" + strconv.Itoa(ts.Servers[0].Port)) + configuration, err := extension.GetConfigCenterFactory("zookeeper").GetDynamicConfiguration(&zkUrl) + config.GetEnvInstance().SetDynamicConfiguration(configuration) + chain, err := NewRouterChain(getConditionRouteUrl("test-condition")) assert.Nil(t, err) - assert.Equal(t, 1, len(chain.routers)) + assert.Equal(t, 2, len(chain.routers)) url := getConditionRouteUrl("test-condition") assert.NotNil(t, url) @@ -105,7 +126,7 @@ func TestRouterChain_AddRouters(t *testing.T) { routers := make([]router.Router, 0) routers = append(routers, r) chain.AddRouters(routers) - assert.Equal(t, 2, len(chain.routers)) + assert.Equal(t, 3, len(chain.routers)) } func getConditionRouteUrl(applicationKey string) *common.URL { -- GitLab