From a41c36eddaea0c76165ac102ec483cc3a93b39e3 Mon Sep 17 00:00:00 2001 From: william feng <> Date: Sun, 19 Jul 2020 00:15:39 +0800 Subject: [PATCH] format the change --- cluster/router/condition/router_rule.go | 4 +- cluster/router/condition/router_rule_test.go | 6 +- cluster/router/condition/router_test.go | 77 ++++++++++---------- common/constant/key.go | 4 +- config/router_config.go | 5 +- config/router_config_test.go | 4 +- 6 files changed, 51 insertions(+), 49 deletions(-) diff --git a/cluster/router/condition/router_rule.go b/cluster/router/condition/router_rule.go index f8c2c3ed0..576dea87f 100644 --- a/cluster/router/condition/router_rule.go +++ b/cluster/router/condition/router_rule.go @@ -26,9 +26,9 @@ import ( ) import ( - "github.com/apache/dubbo-go/common/constant" "github.com/apache/dubbo-go/cluster/router" "github.com/apache/dubbo-go/common" + "github.com/apache/dubbo-go/common/constant" "github.com/apache/dubbo-go/common/yaml" ) @@ -58,7 +58,7 @@ func getRule(rawRule string) (*RouterRule, error) { return r, err } r.RawRule = rawRule - if len(r.Conditions) != 0 && r.Key != "" && (r.Scope == constant.RouterApplicationScope || r.Scope == constant.RouterServiceScope){ + if len(r.Conditions) != 0 && r.Key != "" && (r.Scope == constant.RouterApplicationScope || r.Scope == constant.RouterServiceScope) { r.Valid = true } diff --git a/cluster/router/condition/router_rule_test.go b/cluster/router/condition/router_rule_test.go index 1376058ed..369b14f08 100644 --- a/cluster/router/condition/router_rule_test.go +++ b/cluster/router/condition/router_rule_test.go @@ -73,9 +73,9 @@ key: test-provider conditions: - > method!=sayHello =>` - rule, e = getRule(testyml) - assert.Nil(t, e) - assert.False(t, rule.Valid) + rule, e = getRule(testyml) + assert.Nil(t, e) + assert.False(t, rule.Valid) } func TestIsMatchGlobPattern(t *testing.T) { diff --git a/cluster/router/condition/router_test.go b/cluster/router/condition/router_test.go index 151f6ccfc..35b8656b5 100644 --- a/cluster/router/condition/router_test.go +++ b/cluster/router/condition/router_test.go @@ -15,46 +15,43 @@ * limitations under the License. */ - package condition +package condition - import ( - "testing" - ) - - import ( - "github.com/stretchr/testify/assert" - ) +import ( + "testing" +) - import ( +import ( "github.com/dubbogo/gost/container/set" - ) - - func TestParseRule(t *testing.T) { - testString := `` - matchPair, err := parseRule(testString) - assert.Nil(t, err) - assert.EqualValues(t, matchPair, make(map[string]MatchPair, 16)) - - testString = `method!=sayHello&application=sayGoodBye` - matchPair, err = parseRule(testString) - assert.Nil(t, err) - assert.EqualValues(t, matchPair["method"].Mismatches, gxset.NewSet("sayHello")) - assert.EqualValues(t, matchPair["application"].Matches, gxset.NewSet("sayGoodBye")) - - testString = `noRule` - matchPair, err = parseRule(testString) - assert.Nil(t, err) - assert.EqualValues(t, matchPair["noRule"].Mismatches, gxset.NewSet()) - assert.EqualValues(t, matchPair["noRule"].Matches, gxset.NewSet()) - - testString = `method!=sayHello,sayGoodBye` - matchPair, err = parseRule(testString) - assert.Nil(t, err) - assert.EqualValues(t, matchPair["method"].Mismatches, gxset.NewSet(`sayHello`, `sayGoodBye`)) - - testString = `method!=sayHello,sayGoodDay=sayGoodBye` - matchPair, err = parseRule(testString) - assert.Nil(t, err) - assert.EqualValues(t, matchPair["method"].Mismatches, gxset.NewSet(`sayHello`, `sayGoodDay`)) - assert.EqualValues(t, matchPair["method"].Matches, gxset.NewSet(`sayGoodBye`)) - } \ No newline at end of file + "github.com/stretchr/testify/assert" +) + +func TestParseRule(t *testing.T) { + testString := `` + matchPair, err := parseRule(testString) + assert.Nil(t, err) + assert.EqualValues(t, matchPair, make(map[string]MatchPair, 16)) + + testString = `method!=sayHello&application=sayGoodBye` + matchPair, err = parseRule(testString) + assert.Nil(t, err) + assert.EqualValues(t, matchPair["method"].Mismatches, gxset.NewSet("sayHello")) + assert.EqualValues(t, matchPair["application"].Matches, gxset.NewSet("sayGoodBye")) + + testString = `noRule` + matchPair, err = parseRule(testString) + assert.Nil(t, err) + assert.EqualValues(t, matchPair["noRule"].Mismatches, gxset.NewSet()) + assert.EqualValues(t, matchPair["noRule"].Matches, gxset.NewSet()) + + testString = `method!=sayHello,sayGoodBye` + matchPair, err = parseRule(testString) + assert.Nil(t, err) + assert.EqualValues(t, matchPair["method"].Mismatches, gxset.NewSet(`sayHello`, `sayGoodBye`)) + + testString = `method!=sayHello,sayGoodDay=sayGoodBye` + matchPair, err = parseRule(testString) + assert.Nil(t, err) + assert.EqualValues(t, matchPair["method"].Mismatches, gxset.NewSet(`sayHello`, `sayGoodDay`)) + assert.EqualValues(t, matchPair["method"].Matches, gxset.NewSet(`sayGoodBye`)) +} diff --git a/common/constant/key.go b/common/constant/key.go index 48d7a6dd1..f22debd58 100644 --- a/common/constant/key.go +++ b/common/constant/key.go @@ -197,11 +197,11 @@ const ( // Priority Priority key in router module RouterPriority = "priority" // RouterScope Scope key in router module - RouterScope = "scope" + RouterScope = "scope" // RouterApplicationScope Scope key in router module RouterApplicationScope = "application" // RouterServiceScope Scope key in router module - RouterServiceScope = "service" + RouterServiceScope = "service" // RouterRuleKey defines the key of the router, service's/application's name RouterRuleKey = "key" // ForceUseTag is the tag in attachment diff --git a/config/router_config.go b/config/router_config.go index e9cd5dc74..ed42577ed 100644 --- a/config/router_config.go +++ b/config/router_config.go @@ -33,9 +33,11 @@ var ( routerURLSet = gxset.NewSet() ) +// LocalRouterRules defines the local router config structure type LocalRouterRules struct { RouterRules []interface{} `yaml:"routerRules"` } + // RouterInit Load config file to init router config func RouterInit(confRouterFile string) error { bytes, err := yaml.LoadYMLConfig(confRouterFile) @@ -58,7 +60,7 @@ func RouterInit(confRouterFile string) error { return err } -func initRouterConfig (content []byte,factories map[string]router.FilePriorityRouterFactory) error { +func initRouterConfig(content []byte, factories map[string]router.FilePriorityRouterFactory) error { logger.Warnf("get fileRouterFactories len{%+v})", len(factories)) for k, factory := range factories { r, e := factory.NewFileRouter(content) @@ -72,6 +74,7 @@ func initRouterConfig (content []byte,factories map[string]router.FilePriorityRo return perrors.Errorf("no file router exists for parse %s , implement router.FIleRouterFactory please.", confRouterFile) } +// GetRouterURLSet exposes the routerURLSet func GetRouterURLSet() *gxset.HashSet { return routerURLSet } diff --git a/config/router_config_test.go b/config/router_config_test.go index e4b09ef57..13af7056d 100644 --- a/config/router_config_test.go +++ b/config/router_config_test.go @@ -23,6 +23,7 @@ import ( ) import ( + "github.com/dubbogo/gost/container/set" "github.com/stretchr/testify/assert" ) @@ -65,8 +66,9 @@ func TestRouterInit(t *testing.T) { assert.Equal(t, 1, routerURLSet.Size()) + routerURLSet = gxset.NewSet() errPro = RouterInit(testMultiRouterYML) assert.NoError(t, errPro) - assert.Equal(t, 3, GetRouterURLSet().Size()) + assert.Equal(t, 2, routerURLSet.Size()) } -- GitLab