mirror of
https://github.com/empayre/fleet.git
synced 2024-11-07 17:28:54 +00:00
c269886389
This PR makes the target search more user-friendly by stripping symbols that have a special interpretation in MySQL FTS. Closes #2017
45 lines
760 B
Go
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))
|
|
})
|
|
}
|
|
}
|