fleet/server/datastore/mysql/fulltext_test.go
Zachary Wasserman c269886389
Fix target search behavior with - and + symbols (#2067)
This PR makes the target search more user-friendly by stripping symbols that
have a special interpretation in MySQL FTS.

Closes #2017
2019-07-03 10:47:43 -07:00

45 lines
760 B
Go

package mysql
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestTransformQuery(t *testing.T) {
testCases := []struct {
in string
out string
}{
{"foobar", "foobar*"},
{"tim tom", "tim tom*"},
{"f%5", "f%5*"},
{"f-o-o-b-a-r", "f o o b a r*"},
{"f-o+o-b--+a-r+", "f o o b a r*"},
}
for _, tt := range testCases {
t.Run("", func(t *testing.T) {
assert.Equal(t, tt.out, transformQuery(tt.in))
})
}
}
func TestQueryMinLength(t *testing.T) {
testCases := []struct {
in string
out bool
}{
{"a b c d", false},
{"foobar", true},
{"a foo fim b", true},
{"a fo fi b*", false},
}
for _, tt := range testCases {
t.Run("", func(t *testing.T) {
assert.Equal(t, tt.out, queryMinLength(tt.in))
})
}
}