Skip to content
Snippets Groups Projects
Commit 8073c20d authored by william feng's avatar william feng
Browse files

format the change

parent b03970ef
No related branches found
No related tags found
No related merge requests found
......@@ -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
}
......
......@@ -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) {
......
......@@ -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`))
}
......@@ -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
......
......@@ -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
}
......@@ -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())
}
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