Skip to content

Commit

Permalink
Add tests, fix bug.
Browse files Browse the repository at this point in the history
  • Loading branch information
lkysow committed Nov 3, 2023
1 parent 6bac956 commit e048e52
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 1 deletion.
2 changes: 1 addition & 1 deletion dependency/dependency.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const (
keyRe = `/?(?P<key>[^@]+)`
filterRe = `(\|(?P<filter>[[:word:]\,]+))?`
serviceNameRe = `(?P<name>[[:word:]\-\_]+)`
queryRe = `(?P<query>\?[[:word:]\-\_\=\&]+)`
queryRe = `(?P<query>\?[[:word:]\-\_\=\&]+)?`
nodeNameRe = `(?P<name>[[:word:]\.\-\_]+)`
nearRe = `(~(?P<near>[[:word:]\.\-\_]+))?`
prefixRe = `/?(?P<prefix>[^@]+)`
Expand Down
85 changes: 85 additions & 0 deletions dependency/health_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ func TestNewHealthServiceQuery(t *testing.T) {
nil,
true,
},
{
"query_only",
"?ns=foo",
nil,
true,
},
{
"name",
"name",
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit e048e52

Please sign in to comment.