Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
2
22a7f0099
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Summer2022
22a7f0099
Commits
495d1e04
Commit
495d1e04
authored
5 years ago
by
aliiohs
Browse files
Options
Downloads
Patches
Plain Diff
add test case for url method
parent
90d2caf8
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
cluster/router/condition_router.go
+1
-1
1 addition, 1 deletion
cluster/router/condition_router.go
cluster/router/router_factory.go
+1
-2
1 addition, 2 deletions
cluster/router/router_factory.go
common/url_test.go
+37
-0
37 additions, 0 deletions
common/url_test.go
with
39 additions
and
3 deletions
cluster/router/condition_router.go
+
1
−
1
View file @
495d1e04
...
@@ -227,7 +227,7 @@ func (c *ConditionRouter) MatchThen(url common.URL, param common.URL) (bool, err
...
@@ -227,7 +227,7 @@ func (c *ConditionRouter) MatchThen(url common.URL, param common.URL) (bool, err
func
MatchCondition
(
pairs
map
[
string
]
MatchPair
,
url
*
common
.
URL
,
param
*
common
.
URL
,
invocation
protocol
.
Invocation
)
(
bool
,
error
)
{
func
MatchCondition
(
pairs
map
[
string
]
MatchPair
,
url
*
common
.
URL
,
param
*
common
.
URL
,
invocation
protocol
.
Invocation
)
(
bool
,
error
)
{
sample
:=
url
.
ToMap
()
sample
:=
url
.
ToMap
()
if
sample
==
nil
{
if
sample
==
nil
{
return
true
,
perrors
.
Errorf
(
""
)
return
true
,
perrors
.
Errorf
(
"
url is not allowed be nil
"
)
}
}
result
:=
false
result
:=
false
for
key
,
matchPair
:=
range
pairs
{
for
key
,
matchPair
:=
range
pairs
{
...
...
This diff is collapsed.
Click to expand it.
cluster/router/router_factory.go
+
1
−
2
View file @
495d1e04
...
@@ -10,8 +10,7 @@ func init() {
...
@@ -10,8 +10,7 @@ func init() {
extension
.
SetRouterFactory
(
"condition"
,
NewConditionRouterFactory
)
extension
.
SetRouterFactory
(
"condition"
,
NewConditionRouterFactory
)
}
}
type
ConditionRouterFactory
struct
{
type
ConditionRouterFactory
struct
{}
}
func
NewConditionRouterFactory
()
cluster
.
RouterFactory
{
func
NewConditionRouterFactory
()
cluster
.
RouterFactory
{
return
ConditionRouterFactory
{}
return
ConditionRouterFactory
{}
...
...
This diff is collapsed.
Click to expand it.
common/url_test.go
+
37
−
0
View file @
495d1e04
...
@@ -19,6 +19,7 @@ package common
...
@@ -19,6 +19,7 @@ package common
import
(
import
(
"context"
"context"
"encoding/base64"
"net/url"
"net/url"
"testing"
"testing"
)
)
...
@@ -129,6 +130,42 @@ func TestURL_GetParamBool(t *testing.T) {
...
@@ -129,6 +130,42 @@ func TestURL_GetParamBool(t *testing.T) {
assert
.
Equal
(
t
,
false
,
v
)
assert
.
Equal
(
t
,
false
,
v
)
}
}
func
TestURL_GetParameterAndDecoded
(
t
*
testing
.
T
)
{
rule
:=
"host = 2.2.2.2,1.1.1.1,3.3.3.3 & host !=1.1.1.1 => host = 1.2.3.4"
params
:=
url
.
Values
{}
params
.
Set
(
"rule"
,
base64
.
URLEncoding
.
EncodeToString
([]
byte
(
rule
)))
u
:=
URL
{
baseUrl
:
baseUrl
{
Params
:
params
}}
v
,
_
:=
u
.
GetParameterAndDecoded
(
"rule"
)
assert
.
Equal
(
t
,
rule
,
v
)
}
func
TestURL_GetRawParameter
(
t
*
testing
.
T
)
{
u
,
_
:=
NewURL
(
context
.
TODO
(),
"condition://0.0.0.0:8080/com.foo.BarService?serialization=fastjson"
)
u
.
Username
=
"test"
u
.
Password
=
"test"
assert
.
Equal
(
t
,
"condition"
,
u
.
GetRawParameter
(
"protocol"
))
assert
.
Equal
(
t
,
"0.0.0.0"
,
u
.
GetRawParameter
(
"host"
))
assert
.
Equal
(
t
,
"8080"
,
u
.
GetRawParameter
(
"port"
))
assert
.
Equal
(
t
,
"test"
,
u
.
GetRawParameter
(
"username"
))
assert
.
Equal
(
t
,
"test"
,
u
.
GetRawParameter
(
"password"
))
assert
.
Equal
(
t
,
"/com.foo.BarService"
,
u
.
GetRawParameter
(
"path"
))
assert
.
Equal
(
t
,
"fastjson"
,
u
.
GetRawParameter
(
"serialization"
))
}
func
TestURL_ToMap
(
t
*
testing
.
T
)
{
u
,
_
:=
NewURL
(
context
.
TODO
(),
"condition://0.0.0.0:8080/com.foo.BarService?serialization=fastjson"
)
u
.
Username
=
"test"
u
.
Password
=
"test"
m
:=
u
.
ToMap
()
assert
.
Equal
(
t
,
7
,
len
(
m
))
assert
.
Equal
(
t
,
"condition"
,
m
[
"protocol"
])
assert
.
Equal
(
t
,
"0.0.0.0"
,
m
[
"host"
])
assert
.
Equal
(
t
,
"8080"
,
m
[
"port"
])
assert
.
Equal
(
t
,
"test"
,
m
[
"username"
])
assert
.
Equal
(
t
,
"test"
,
m
[
"password"
])
assert
.
Equal
(
t
,
"/com.foo.BarService"
,
m
[
"path"
])
assert
.
Equal
(
t
,
"fastjson"
,
m
[
"serialization"
])
}
func
TestURL_GetMethodParamInt
(
t
*
testing
.
T
)
{
func
TestURL_GetMethodParamInt
(
t
*
testing
.
T
)
{
params
:=
url
.
Values
{}
params
:=
url
.
Values
{}
params
.
Set
(
"methods.GetValue.timeout"
,
"3"
)
params
.
Set
(
"methods.GetValue.timeout"
,
"3"
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment