Merge pull request #9746 from neoaggelos/fix/config-glob
Fix config import relative path glob
This commit is contained in:
commit
d346aeebdf
@ -373,6 +373,11 @@ func resolveImports(parent string, imports []string) ([]string, error) {
|
|||||||
var out []string
|
var out []string
|
||||||
|
|
||||||
for _, path := range imports {
|
for _, path := range imports {
|
||||||
|
path = filepath.Clean(path)
|
||||||
|
if !filepath.IsAbs(path) {
|
||||||
|
path = filepath.Join(filepath.Dir(parent), path)
|
||||||
|
}
|
||||||
|
|
||||||
if strings.Contains(path, "*") {
|
if strings.Contains(path, "*") {
|
||||||
matches, err := filepath.Glob(path)
|
matches, err := filepath.Glob(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -381,11 +386,6 @@ func resolveImports(parent string, imports []string) ([]string, error) {
|
|||||||
|
|
||||||
out = append(out, matches...)
|
out = append(out, matches...)
|
||||||
} else {
|
} else {
|
||||||
path = filepath.Clean(path)
|
|
||||||
if !filepath.IsAbs(path) {
|
|
||||||
path = filepath.Join(filepath.Dir(parent), path)
|
|
||||||
}
|
|
||||||
|
|
||||||
out = append(out, path)
|
out = append(out, path)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -105,6 +105,17 @@ func TestResolveImports(t *testing.T) {
|
|||||||
filepath.Join(tempDir, "test.toml"),
|
filepath.Join(tempDir, "test.toml"),
|
||||||
filepath.Join(tempDir, "current.toml"),
|
filepath.Join(tempDir, "current.toml"),
|
||||||
})
|
})
|
||||||
|
|
||||||
|
t.Run("GlobRelativePath", func(t *testing.T) {
|
||||||
|
imports, err := resolveImports(filepath.Join(tempDir, "root.toml"), []string{
|
||||||
|
"config_*.toml", // Glob files from working dir
|
||||||
|
})
|
||||||
|
assert.NoError(t, err)
|
||||||
|
assert.Equal(t, imports, []string{
|
||||||
|
filepath.Join(tempDir, "config_1.toml"),
|
||||||
|
filepath.Join(tempDir, "config_2.toml"),
|
||||||
|
})
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestLoadSingleConfig(t *testing.T) {
|
func TestLoadSingleConfig(t *testing.T) {
|
||||||
|
Loading…
Reference in New Issue
Block a user