Separate underlay acquisition from composition
This commit is contained in:
@@ -73,6 +73,50 @@ items: [{id: b}]
|
||||
}
|
||||
}
|
||||
|
||||
func TestUnderlayGroupAcquisitionRetainsScopesUntilComposition(t *testing.T) {
|
||||
filesystem := NewFilesystem("handoff", fstest.MapFS{
|
||||
"main.yml": &fstest.MapFile{Data: []byte("configkit: {imports: [{path: child.yml}]}\nmain: retained\n")},
|
||||
"child.yml": &fstest.MapFile{Data: []byte("child: retained\n")},
|
||||
})
|
||||
accounting := &importAccounting{}
|
||||
group := loadGroup{inputs: []loadInput{{source: filesystem.File("main.yml"), imports: true}}}
|
||||
acquired, diagnostics := acquireUnderlayGroupScopes(group, 2, nil, accounting, nil, sequencePolicy{})
|
||||
if len(diagnostics) != 0 {
|
||||
t.Fatalf("acquire underlay group: %#v", diagnostics)
|
||||
}
|
||||
if acquired == nil || acquired.index != 2 || len(acquired.scopes) != 1 || len(acquired.scopes[0].contributions) != 2 {
|
||||
t.Fatalf("acquisition handoff lost its source scope: %#v", acquired)
|
||||
}
|
||||
if len(acquired.sources) != 2 || acquired.sources[0].UnderlayIndex != 2 || acquired.sources[1].ID != "source-2" {
|
||||
t.Fatalf("acquired source evidence = %#v", acquired.sources)
|
||||
}
|
||||
if acquired.inputBytes != int64(len("configkit: {imports: [{path: child.yml}]}\nmain: retained\n")+len("child: retained\n")) {
|
||||
t.Fatalf("group input byte accounting = %d", acquired.inputBytes)
|
||||
}
|
||||
|
||||
composition, diagnostics := composeUnderlayGroup(acquired, nil, sequencePolicy{}, collectionPolicyScope{})
|
||||
if len(diagnostics) != 0 {
|
||||
t.Fatalf("compose acquired group: %#v", diagnostics)
|
||||
}
|
||||
for key, want := range map[string]string{"main": "retained", "child": "retained"} {
|
||||
value, present := documentAtPath(composition.root, Keys(key))
|
||||
if !present || value.Text != want {
|
||||
t.Errorf("composed %s = %#v, %v; want %q", key, value, present, want)
|
||||
}
|
||||
}
|
||||
if composition.inputBytes != acquired.inputBytes || len(composition.acquisition) != 1 || len(composition.acquisition[0].contributions) != 2 {
|
||||
t.Fatalf("composed group handoff = %#v", composition)
|
||||
}
|
||||
|
||||
empty, diagnostics := acquireUnderlayGroupScopes(loadGroup{}, 3, nil, accounting, nil, sequencePolicy{})
|
||||
if len(diagnostics) != 0 || len(empty.scopes) != 0 {
|
||||
t.Fatalf("empty group acquisition = %#v, %#v", empty, diagnostics)
|
||||
}
|
||||
if composition, diagnostics := composeUnderlayGroup(empty, nil, sequencePolicy{}, collectionPolicyScope{}); len(diagnostics) != 0 || composition != nil {
|
||||
t.Fatalf("empty group composition = %#v, %#v", composition, diagnostics)
|
||||
}
|
||||
}
|
||||
|
||||
func TestUnderlayNamespaceAnchorsUseInputPositionsAndFilesystemIdentity(t *testing.T) {
|
||||
firstNamespace := NewFilesystem("same-label", fstest.MapFS{
|
||||
"root.yml": &fstest.MapFile{Data: []byte("items: [{id: first}]\n")},
|
||||
|
||||
Reference in New Issue
Block a user