Separate input acquisition from composition
This commit is contained in:
@@ -601,6 +601,65 @@ func TestProjectNestedEvidenceUsesMappedSequenceItemIndex(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestDeferredInputCompositionUsesRetainedAcquisitionScopes(t *testing.T) {
|
||||
directory := t.TempDir()
|
||||
mainPath := writeImportFile(t, directory, "main.yml", `configkit:
|
||||
imports:
|
||||
- path: item.yml
|
||||
destination: [records]
|
||||
placement: sequence-item
|
||||
name: main
|
||||
`)
|
||||
itemPath := writeImportFile(t, directory, "item.yml", `configkit:
|
||||
imports:
|
||||
- path: helper.yml
|
||||
id: item
|
||||
`)
|
||||
helperPath := writeImportFile(t, directory, "helper.yml", "value: acquired\n")
|
||||
accounting := &importAccounting{}
|
||||
input, diagnostics := assembleBaseInputTracked(File(mainPath), Options[struct{}]{
|
||||
Imports: true, Filesystem: &FilesystemContext{Root: directory}, deferAssembly: true,
|
||||
}, Path{}, accounting, nil, nil)
|
||||
if len(diagnostics) != 0 {
|
||||
t.Fatalf("acquire input: %#v", diagnostics)
|
||||
}
|
||||
if input.composition == nil || input.composition.root != nil || len(input.composition.acquisition) != 1 {
|
||||
t.Fatalf("acquisition handoff was composed early: %#v", input.composition)
|
||||
}
|
||||
if len(input.sources) != 3 || input.sources[0].ID != "source-1" || input.sources[1].ID != "source-2" || input.sources[2].ID != "source-3" {
|
||||
t.Fatalf("acquired source order/identity = %#v", input.sources)
|
||||
}
|
||||
if _, err := os.Stat(itemPath); err != nil {
|
||||
t.Fatalf("item source disappeared before composition: %v", err)
|
||||
}
|
||||
if _, err := os.Stat(helperPath); err != nil {
|
||||
t.Fatalf("helper source disappeared before composition: %v", err)
|
||||
}
|
||||
|
||||
composition, diagnostics := compositionForInputWithPolicy(input, sequencePolicy{})
|
||||
if len(diagnostics) != 0 {
|
||||
t.Fatalf("compose acquired input: %#v", diagnostics)
|
||||
}
|
||||
if value, present := documentAtPath(composition.root, Keys("name")); !present || value.Text != "main" {
|
||||
t.Fatalf("main value = %#v, %v", value, present)
|
||||
}
|
||||
for path, want := range map[string]string{
|
||||
"/records/0/id": "item",
|
||||
"/records/0/value": "acquired",
|
||||
} {
|
||||
value, present := documentAtPath(composition.root, mustParsePath(t, path))
|
||||
if !present || value.Text != want {
|
||||
t.Errorf("composed %s = %#v, %v; want %q", path, value, present, want)
|
||||
}
|
||||
}
|
||||
if got, want := input.sources[1].Destination.String(), "/records"; got != want {
|
||||
t.Errorf("item destination = %q, want %q", got, want)
|
||||
}
|
||||
if got, want := input.sources[2].Destination.String(), "/records/0"; got != want {
|
||||
t.Errorf("helper destination = %q, want %q", got, want)
|
||||
}
|
||||
}
|
||||
|
||||
func TestItemImportCanJoinAnAuthoredListUnderRegisteredComposition(t *testing.T) {
|
||||
t.Parallel()
|
||||
type config struct {
|
||||
|
||||
Reference in New Issue
Block a user