-
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
Showing
8 changed files
with
184 additions
and
42 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
34 changes: 34 additions & 0 deletions
34
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,34 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
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
72 changes: 72 additions & 0 deletions
72
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,72 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
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)) | ||
} |
35 changes: 35 additions & 0 deletions
35
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,35 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
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
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