Reuse owned assembly across configuration layers
This commit is contained in:
@@ -76,3 +76,44 @@ to_scalar: scalar
|
||||
t.Fatal("overlay result aliases an input document")
|
||||
}
|
||||
}
|
||||
|
||||
func TestOwnedOverlayKeepsCompositeContributorsAndAcquiredInputs(t *testing.T) {
|
||||
baseInput := parseCompositionDocument(t, "source-1", "catalog:\n base: true\n")
|
||||
base, diagnostics := composeDocuments(baseInput)
|
||||
if len(diagnostics) != 0 {
|
||||
t.Fatal(diagnostics)
|
||||
}
|
||||
first := parseCompositionDocument(t, "source-2", "catalog:\n first: true\n")
|
||||
second := parseCompositionDocument(t, "source-3", "catalog:\n second: true\n")
|
||||
firstBefore, secondBefore := document.Clone(first), document.Clone(second)
|
||||
incoming, diagnostics := composeDocuments(first, second)
|
||||
if len(diagnostics) != 0 {
|
||||
t.Fatal(diagnostics)
|
||||
}
|
||||
assembly := newAssemblyAccumulator(base)
|
||||
if diagnostics := assembly.applyOverlay(incoming.root, incoming.origins, incoming.applications, LayerOverlay); len(diagnostics) != 0 {
|
||||
t.Fatal(diagnostics)
|
||||
}
|
||||
for _, key := range []string{"base", "first", "second"} {
|
||||
if _, ok := documentAtPath(assembly.current.root, Keys("catalog", key)); !ok {
|
||||
t.Fatalf("catalog is missing %q", key)
|
||||
}
|
||||
}
|
||||
origin := assembly.current.origins[Keys("catalog").String()]
|
||||
if got, want := origin.Locations, []Location{{SourceID: "source-1", Line: 2, Column: 3}, {SourceID: "source-2", Line: 2, Column: 3}, {SourceID: "source-3", Line: 2, Column: 3}}; !reflect.DeepEqual(got, want) {
|
||||
t.Fatalf("catalog origin locations = %#v, want %#v", got, want)
|
||||
}
|
||||
if len(assembly.current.applications) != 3 {
|
||||
t.Fatalf("history applications = %d, want three source contributions", len(assembly.current.applications))
|
||||
}
|
||||
for _, application := range assembly.current.applications[1:] {
|
||||
if application.layer != LayerOverlay {
|
||||
t.Fatalf("incoming application layer = %q", application.layer)
|
||||
}
|
||||
}
|
||||
assembly.current.root.Mapping[0].Value.Mapping[1].Value.Text = "false"
|
||||
if !reflect.DeepEqual(first, firstBefore) || !reflect.DeepEqual(second, secondBefore) ||
|
||||
!reflect.DeepEqual(first, assembly.current.applications[1].value) || !reflect.DeepEqual(second, assembly.current.applications[2].value) {
|
||||
t.Fatal("working tree mutation changed an acquired input")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user