Materialize glob expansion in configuration struct (#217)

This is needed to figure out which files should adhere to the schema.
This commit is contained in:
Pieter Noordhuis 2023-02-20 21:01:28 +01:00 committed by GitHub
parent 7398a6d1e4
commit 9912ee1f92
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 0 deletions

View File

@ -30,6 +30,10 @@ func (m *processRootIncludes) Apply(_ context.Context, b *bundle.Bundle) ([]bund
config.FileName: true,
}
// Maintain list of files in order of files being loaded.
// This is stored in the bundle configuration for observability.
var files []string
// For each glob, find all files to load.
// Ordering of the list of globs is maintained in the output.
// For matches that appear in multiple globs, only the first is kept.
@ -61,10 +65,14 @@ func (m *processRootIncludes) Apply(_ context.Context, b *bundle.Bundle) ([]bund
// Add matches to list of mutators to return.
slices.Sort(includes)
files = append(files, includes...)
for _, include := range includes {
out = append(out, ProcessInclude(filepath.Join(b.Config.Path, include), include))
}
}
// Swap out the original includes list with the expanded globs.
b.Config.Include = files
return out, nil
}

View File

@ -76,6 +76,7 @@ func TestProcessRootIncludesSingleGlob(t *testing.T) {
assert.NotContains(t, names, "ProcessInclude(bundle.yml)")
assert.Contains(t, names, "ProcessInclude(a.yml)")
assert.Contains(t, names, "ProcessInclude(b.yml)")
assert.Equal(t, []string{"a.yml", "b.yml"}, bundle.Config.Include)
}
func TestProcessRootIncludesMultiGlob(t *testing.T) {
@ -102,6 +103,7 @@ func TestProcessRootIncludesMultiGlob(t *testing.T) {
assert.Contains(t, names, "ProcessInclude(a1.yml)")
assert.Contains(t, names, "ProcessInclude(b1.yml)")
assert.Equal(t, []string{"a1.yml", "b1.yml"}, bundle.Config.Include)
}
func TestProcessRootIncludesRemoveDups(t *testing.T) {
@ -121,4 +123,5 @@ func TestProcessRootIncludesRemoveDups(t *testing.T) {
require.NoError(t, err)
assert.Len(t, ms, 1)
assert.Equal(t, "ProcessInclude(a.yml)", ms[0].Name())
assert.Equal(t, []string{"a.yml"}, bundle.Config.Include)
}