Fix comment on SplitIndexNameValue

It was incorrect and suggested some behaviour which isn't present.
Added test to verify the documented behaviour.
This commit is contained in:
Justin SB
2020-09-11 11:39:49 -04:00
parent 6df0a45368
commit 341bacb9a2
2 changed files with 6 additions and 1 deletions

View File

@@ -605,7 +605,7 @@ func IsListIndex(p string) bool {
// SplitIndexNameValue splits a lookup part Val index into the field name
// and field value to match.
// e.g. splits [name=nginx] into (name, nginx)
// e.g. splits [=-jar] into ("", jar)
// e.g. splits [=-jar] into ("", -jar)
func SplitIndexNameValue(p string) (string, string, error) {
elem := strings.TrimSuffix(p, "]")
elem = strings.TrimPrefix(elem, "[")

View File

@@ -518,6 +518,11 @@ func TestSplitIndexNameValue(t *testing.T) {
assert.NoError(t, err)
assert.Equal(t, "a", k)
assert.Equal(t, "b=c", v)
k, v, err = SplitIndexNameValue("=-jar")
assert.NoError(t, err)
assert.Equal(t, "", k)
assert.Equal(t, "-jar", v)
}
type filter struct {