Keep import selection evidence with its declaring source
This commit is contained in:
@@ -2,11 +2,54 @@ package engine
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"path/filepath"
|
||||
"reflect"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestBroadEmptyImportSelectionsKeepDeclaringSourceOwnership(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
directory := t.TempDir()
|
||||
mainPath := writeImportFile(t, directory, "main.yml", `configkit:
|
||||
imports:
|
||||
- glob: fragments/*.yml
|
||||
- path: []
|
||||
`)
|
||||
const fragments = 32
|
||||
for index := 0; index < fragments; index++ {
|
||||
writeImportFile(t, directory, fmt.Sprintf("fragments/fragment-%02d.yml", index), `configkit:
|
||||
imports:
|
||||
- path: missing.yml
|
||||
- path: []
|
||||
`)
|
||||
}
|
||||
loaded, err := testLoad[map[string]any](File(mainPath), Options[map[string]any]{Imports: true})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
sources := loaded.Sources()
|
||||
if len(sources) != fragments+1 {
|
||||
t.Fatalf("source count = %d, want %d", len(sources), fragments+1)
|
||||
}
|
||||
for index, source := range sources {
|
||||
wantPaths := []string{"/configkit/imports/0", "/configkit/imports/1"}
|
||||
if index == 0 {
|
||||
wantPaths = wantPaths[1:]
|
||||
}
|
||||
if len(source.importSelections) != len(wantPaths) {
|
||||
t.Fatalf("source %s selections = %#v", source.ID, source.importSelections)
|
||||
}
|
||||
for selectionIndex, selection := range source.importSelections {
|
||||
if selection.path.String() != wantPaths[selectionIndex] || selection.location.SourceID != source.ID ||
|
||||
selection.selector != importSelectorPath || selection.outcome != importSelectionNone {
|
||||
t.Errorf("source %s selection %d = %#v", source.ID, selectionIndex, selection)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestOptionalEmptyImportSelectionsRemainSourceLocalAndDetached(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user