-
Notifications
You must be signed in to change notification settings - Fork 929
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
make the package v3router/judger test coverage rate reach 80%
- Loading branch information
dongjianhui
committed
Jun 15, 2021
1 parent
5c2e47e
commit 80c2eb2
Showing
7 changed files
with
131 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
cluster/router/v3router/judger/list_string_match_judger_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package judger | ||
|
||
import ( | ||
"dubbo.apache.org/dubbo-go/v3/config" | ||
"github.com/stretchr/testify/assert" | ||
"testing" | ||
) | ||
|
||
func TestListStringMatchJudger(t *testing.T) { | ||
assert.True(t, newListStringMatchJudger(&config.ListStringMatch{ | ||
Oneof: []*config.StringMatch{{Exact: "abd"}}, | ||
}).Judge("abd")) | ||
|
||
assert.False(t, newListStringMatchJudger(&config.ListStringMatch{ | ||
Oneof: []*config.StringMatch{{Exact: "abc"}}, | ||
}).Judge("abd")) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
cluster/router/v3router/judger/method_match_judger_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package judger | ||
|
||
import ( | ||
"dubbo.apache.org/dubbo-go/v3/config" | ||
"dubbo.apache.org/dubbo-go/v3/protocol/invocation" | ||
"github.com/stretchr/testify/assert" | ||
"reflect" | ||
"testing" | ||
) | ||
|
||
func TestMethodMatchJudger(t *testing.T) { | ||
|
||
methodArgs := make([]*config.DubboMethodArg, 0) | ||
methodArgs = append(methodArgs, &config.DubboMethodArg{ | ||
Index: 1, | ||
Type: "string", | ||
StrValue: &config.ListStringMatch{Oneof: []*config.StringMatch{{Exact: "hello world"}}}, | ||
NumValue: nil, | ||
BoolValue: nil, | ||
}) | ||
methodArgs = append(methodArgs, &config.DubboMethodArg{ | ||
Index: 2, | ||
Type: "bool", | ||
StrValue: nil, | ||
NumValue: nil, | ||
BoolValue: &config.BoolMatch{Exact: true}, | ||
}) | ||
methodArgs = append(methodArgs, &config.DubboMethodArg{ | ||
Index: 3, | ||
Type: "float64", | ||
StrValue: nil, | ||
NumValue: &config.ListDoubleMatch{Oneof: []*config.DoubleMatch{{Exact: 10}}}, | ||
BoolValue: nil, | ||
}) | ||
|
||
methodMatch := &config.DubboMethodMatch{ | ||
NameMatch: &config.StringMatch{Exact: "Greet"}, | ||
Argc: 3, | ||
Args: methodArgs, | ||
Argp: nil, | ||
Headers: nil, | ||
} | ||
|
||
stringValue := reflect.ValueOf("hello world") | ||
boolValue := reflect.ValueOf(true) | ||
numValue := reflect.ValueOf(10.0) | ||
ivc := invocation.NewRPCInvocationWithOptions( | ||
invocation.WithMethodName("Greet"), | ||
invocation.WithParameterValues([]reflect.Value{stringValue, boolValue, numValue}), | ||
) | ||
|
||
assert.False(t, NewMethodMatchJudger(&config.DubboMethodMatch{NameMatch: &config.StringMatch{Exact: "Great"}}).Judge(ivc)) | ||
assert.False(t, NewMethodMatchJudger(&config.DubboMethodMatch{NameMatch: &config.StringMatch{Exact: "Greet"}, Argc: 1}).Judge(ivc)) | ||
assert.True(t, NewMethodMatchJudger(methodMatch).Judge(ivc)) | ||
} |
18 changes: 18 additions & 0 deletions
18
cluster/router/v3router/judger/url_label_match_judge_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package judger | ||
|
||
import ( | ||
"dubbo.apache.org/dubbo-go/v3/common" | ||
"github.com/stretchr/testify/assert" | ||
"testing" | ||
) | ||
|
||
func TestJudgeUrlLabel(t *testing.T) { | ||
url := common.NewURLWithOptions(common.WithParamsValue("a", "A")) | ||
|
||
labels := make(map[string]string) | ||
labels["a"] = "A" | ||
assert.True(t, JudgeUrlLabel(url, labels)) | ||
|
||
labels["a"] = "B" | ||
assert.False(t, JudgeUrlLabel(url, labels)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters