diff --git a/dependency/dependency.go b/dependency/dependency.go index 5b9c27a85..8dde80b18 100644 --- a/dependency/dependency.go +++ b/dependency/dependency.go @@ -19,7 +19,7 @@ const ( keyRe = `/?(?P[^@]+)` filterRe = `(\|(?P[[:word:]\,]+))?` serviceNameRe = `(?P[[:word:]\-\_]+)` - queryRe = `(?P\?[[:word:]\-\_\=\&]+)` + queryRe = `(?P\?[[:word:]\-\_\=\&]+)?` nodeNameRe = `(?P[[:word:]\.\-\_]+)` nearRe = `(~(?P[[:word:]\.\-\_]+))?` prefixRe = `/?(?P[^@]+)` diff --git a/dependency/health_service_test.go b/dependency/health_service_test.go index e5151cdba..3974560f6 100644 --- a/dependency/health_service_test.go +++ b/dependency/health_service_test.go @@ -42,6 +42,12 @@ func TestNewHealthServiceQuery(t *testing.T) { nil, true, }, + { + "query_only", + "?ns=foo", + nil, + true, + }, { "name", "name", @@ -126,6 +132,85 @@ func TestNewHealthServiceQuery(t *testing.T) { }, false, }, + { + "name_partition", + "name?partition=foo", + &HealthServiceQuery{ + filters: []string{"passing"}, + name: "name", + partition: "foo", + }, + false, + }, + { + "name_peer", + "name?peer=foo", + &HealthServiceQuery{ + filters: []string{"passing"}, + name: "name", + peer: "foo", + }, + false, + }, + { + "name_ns", + "name?ns=foo", + &HealthServiceQuery{ + filters: []string{"passing"}, + name: "name", + namespace: "foo", + }, + false, + }, + { + "name_ns_peer_partition", + "name?ns=foo&peer=bar&partition=baz", + &HealthServiceQuery{ + filters: []string{"passing"}, + name: "name", + namespace: "foo", + peer: "bar", + partition: "baz", + }, + false, + }, + { + "name_ns_ns", + "name?ns=foo&ns=bar", + &HealthServiceQuery{ + filters: []string{"passing"}, + name: "name", + namespace: "bar", + }, + false, + }, + { + "empty value in query param", + "name?ns=&peer=&partition=", + &HealthServiceQuery{ + filters: []string{"passing"}, + name: "name", + namespace: "", + peer: "", + partition: "", + }, + false, + }, + { + name: "invalid query param (extra =)", + i: "name?ns==", + err: true, + }, + { + name: "invalid query param (no =)", + i: "name?ns", + err: true, + }, + { + name: "invalid query param (unsupported key)", + i: "name?unsupported=test", + err: true, + }, } for i, tc := range cases {