Make names case insensitive for API

This commit is contained in:
breel
2020-07-25 13:58:02 -06:00
parent 34075cf19a
commit ee4f23a9f4
6 changed files with 75 additions and 32 deletions

View File

@@ -7,6 +7,7 @@ import (
"local/dndex/storage/entity"
"local/dndex/storage/operator"
"os"
"strings"
"testing"
"time"
@@ -45,40 +46,54 @@ func TestBoltDBCount(t *testing.T) {
}
for name, filter := range map[string]struct {
filter interface{}
match bool
filter interface{}
matchOne bool
matchMany bool
}{
"one.Query": {
filter: ones[0].Query(),
match: true,
filter: ones[0].Query(),
matchOne: true,
},
"title:title": {
filter: map[string]interface{}{entity.Title: ones[1].Title},
match: true,
filter: map[string]interface{}{entity.Title: ones[1].Title},
matchOne: true,
},
"title:title, text:text": {
filter: map[string]interface{}{entity.Title: ones[2].Title, entity.Text: ones[2].Text},
match: true,
filter: map[string]interface{}{entity.Title: ones[2].Title, entity.Text: ones[2].Text},
matchOne: true,
},
"title:title, text:gibberish": {
filter: map[string]interface{}{entity.Title: ones[3].Title, entity.Text: ones[2].Text},
match: false,
},
"name:$in[gibberish]": {
filter: operator.NewFilterIn(entity.Name, []string{ones[0].Name + ones[1].Name}),
match: false,
},
"name:$in[name]": {
filter: operator.NewFilterIn(entity.Name, []string{ones[0].Name}),
match: true,
filter: operator.NewFilterIn(entity.Name, []string{ones[0].Name}),
matchOne: true,
},
"name:$regex[gibberish]": {
filter: operator.Regex{Key: entity.Name, Value: ones[3].Name + ones[4].Name},
match: false,
},
"name:$regex[name]": {
filter: operator.Regex{Key: entity.Name, Value: ones[3].Name},
match: true,
filter: operator.Regex{Key: entity.Name, Value: ones[3].Name},
matchOne: true,
},
"name:caseInsensitive[]": {
filter: operator.CaseInsensitive{Key: entity.Name, Value: ""},
matchMany: true,
},
"name:caseInsensitive[NAME]": {
filter: operator.CaseInsensitive{Key: entity.Name, Value: strings.ToUpper(ones[3].Name)},
matchOne: true,
},
"name:caseInsensitives[[]{}]": {
filter: operator.CaseInsensitives{Key: entity.Name, Values: []string{}},
matchMany: true,
},
"name:caseInsensitives[[]{NAME}]": {
filter: operator.CaseInsensitives{Key: entity.Name, Values: []string{strings.ToUpper(ones[3].Name)}},
matchOne: true,
},
} {
f := filter
@@ -87,10 +102,12 @@ func TestBoltDBCount(t *testing.T) {
if err != nil {
t.Fatal(err)
}
if f.match && n != 1 {
t.Fatalf("%v results for %+v, want match=%v", n, f, f.match)
} else if !f.match && n != 0 {
t.Fatalf("%v results for %+v, want match=%v", n, f, f.match)
if f.matchOne && n != 1 {
t.Fatalf("%v results for %+v, want matchOne=%v", n, f, f.matchOne)
} else if f.matchMany && n < 2 {
t.Fatalf("%v results for %+v, want matchMany=%v", n, f, f.matchMany)
} else if !f.matchOne && !f.matchMany && n != 0 {
t.Fatalf("%v results for %+v, want match=%v", n, f, f.matchOne || f.matchMany)
}
})
}