Improve performance of globpath with some patterns (#4836)

This commit is contained in:
Samuel-BF
2018-10-12 23:48:11 +02:00
committed by Daniel Nelson
parent a2ac9115b3
commit f259229a35
2 changed files with 29 additions and 55 deletions

View File

@@ -6,7 +6,6 @@ import (
"strings"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
@@ -29,31 +28,32 @@ func TestCompileAndMatch(t *testing.T) {
require.NoError(t, err)
matches := g1.Match()
assert.Len(t, matches, 6)
require.Len(t, matches, 6)
matches = g2.Match()
assert.Len(t, matches, 2)
require.Len(t, matches, 2)
matches = g3.Match()
assert.Len(t, matches, 1)
require.Len(t, matches, 1)
matches = g4.Match()
assert.Len(t, matches, 0)
require.Len(t, matches, 0)
matches = g5.Match()
assert.Len(t, matches, 0)
require.Len(t, matches, 0)
}
func TestFindRootDir(t *testing.T) {
func TestRootGlob(t *testing.T) {
dir := getTestdataDir()
tests := []struct {
input string
output string
}{
{"/var/log/telegraf.conf", "/var/log"},
{"/home/**", "/home"},
{"/home/*/**", "/home"},
{"/lib/share/*/*/**.txt", "/lib/share"},
{dir + "/**", dir + "/*"},
{dir + "/nested?/**", dir + "/nested?/*"},
{dir + "/ne**/nest*", dir + "/ne*"},
{dir + "/nested?/*", ""},
}
for _, test := range tests {
actual := findRootDir(test.input)
assert.Equal(t, test.output, actual)
actual, _ := Compile(test.input)
require.Equal(t, actual.rootGlob, test.output)
}
}
@@ -64,7 +64,7 @@ func TestFindNestedTextFile(t *testing.T) {
require.NoError(t, err)
matches := g1.Match()
assert.Len(t, matches, 1)
require.Len(t, matches, 1)
}
func getTestdataDir() string {