From bb91f0f1a5bec08ad2e6f03ff97a81628aae5451 Mon Sep 17 00:00:00 2001 From: Joe Zou <yixian.zou@gmail.com> Date: Wed, 22 Jan 2020 11:38:20 +0800 Subject: [PATCH] update test case --- cluster/router/chain/chain_test.go | 21 ++++++++++++++++--- cluster/router/condition/listenable_router.go | 5 +++++ 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/cluster/router/chain/chain_test.go b/cluster/router/chain/chain_test.go index 7a15ab620..0389977cf 100644 --- a/cluster/router/chain/chain_test.go +++ b/cluster/router/chain/chain_test.go @@ -19,6 +19,7 @@ package chain import ( "context" + "github.com/apache/dubbo-go/cluster/router/condition" "github.com/apache/dubbo-go/common" "github.com/apache/dubbo-go/common/config" "github.com/apache/dubbo-go/common/extension" @@ -40,14 +41,14 @@ func TestNewRouterChain(t *testing.T) { err = z.Create("/dubbo/config/dubbo/test-condition.condition-router") assert.NoError(t, err) - data := `enabled: true + 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(data), 0) + _, err = z.Conn.Set("/dubbo/config/dubbo/test-condition.condition-router", []byte(testyml), 0) assert.NoError(t, err) defer ts.Stop() defer z.Close() @@ -62,7 +63,21 @@ conditions: assert.NotNil(t, configuration) chain := NewRouterChain(getRouteUrl("test-condition")) - t.Log(chain.routers) + assert.Equal(t, 1, len(chain.routers)) + appRouter := chain.routers[0].(*condition.AppRouter) + + assert.NotNil(t, appRouter) + assert.NotNil(t, appRouter.RouterRule()) + rule := appRouter.RouterRule() + assert.Equal(t, "", rule.Scope) + assert.True(t, rule.Force) + assert.True(t, rule.Enabled) + assert.True(t, rule.Valid) + + assert.Equal(t, testyml, rule.RawRule) + assert.Equal(t, false, rule.Runtime) + assert.Equal(t, false, rule.Dynamic) + assert.Equal(t, "", rule.Key) } func getRouteUrl(applicationKey string) *common.URL { diff --git a/cluster/router/condition/listenable_router.go b/cluster/router/condition/listenable_router.go index 8d8de42eb..0a386cc36 100644 --- a/cluster/router/condition/listenable_router.go +++ b/cluster/router/condition/listenable_router.go @@ -49,6 +49,10 @@ type listenableRouter struct { priority int64 } +func (l *listenableRouter) RouterRule() *RouterRule { + return l.routerRule +} + func newListenableRouter(url *common.URL, ruleKey string) (*AppRouter, error) { if ruleKey == "" { return nil, perrors.Errorf("newListenableRouter ruleKey is nil, can't create Listenable router") @@ -106,6 +110,7 @@ func (l *listenableRouter) generateConditions(rule *RouterRule) { return } l.conditionRouters = make([]*ConditionRouter, 0) + l.routerRule = rule for _, c := range rule.Conditions { router, e := NewConditionRouterWithRule(c) if e != nil { -- GitLab