Index tier history sources lazily
This commit is contained in:
@@ -11,17 +11,18 @@ import (
|
||||
|
||||
func TestSequenceHistoryReplaysAppendAtAssignedIndexes(t *testing.T) {
|
||||
policy := mustCompileSequenceIdentityPolicy(t, []sequenceIdentityRegistration{
|
||||
{selector: sequenceIdentitySelector{literalSequenceSelector("records")}, identityFields: []string{"id"}},
|
||||
{selector: sequenceIdentitySelector{literalSequenceSelector("other")}, identityFields: []string{"id"}},
|
||||
{selector: sequenceIdentitySelector{
|
||||
literalSequenceSelector("collections"), anyMappingSequenceSelector(), literalSequenceSelector("records"),
|
||||
}, identityFields: []string{"id"}},
|
||||
})
|
||||
first := parseCompositionDocument(t, "source-1", "records: [{id: a, value: first}]\nother: [{id: x}]\n")
|
||||
second := parseCompositionDocument(t, "source-2", "records: [{id: b, value: second}]\nother: [{id: y}]\n")
|
||||
first := parseCompositionDocument(t, "source-1", "collections: {north: {records: [{id: a, value: first}]}, south: {records: [{id: x}]}}\n")
|
||||
second := parseCompositionDocument(t, "source-2", "collections: {north: {records: [{id: b, value: second}]}, south: {records: [{id: y}]}}\n")
|
||||
composed, diagnostics := composeDocumentsWithPolicy(policy, first, second)
|
||||
if len(diagnostics) != 0 {
|
||||
t.Fatalf("compose diagnostics = %#v", diagnostics)
|
||||
}
|
||||
for applicationIndex, application := range composed.applications {
|
||||
for path, want := range map[string]int{"/records": 1, "/other": 1} {
|
||||
for path, want := range map[string]int{"/collections/north/records": 1, "/collections/south/records": 1} {
|
||||
sequence, present := documentAtPath(application.value, mustParsePath(t, path))
|
||||
if !present || sequence.Kind != document.Sequence || len(sequence.Sequence) != want {
|
||||
t.Errorf("application %d retained %s = %#v, %v; want one source fragment item", applicationIndex, path, sequence, present)
|
||||
@@ -29,14 +30,14 @@ func TestSequenceHistoryReplaysAppendAtAssignedIndexes(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
working := parseCompositionDocument(t, "defaults", "records: [{id: default}]\nother: [{id: default}]\n")
|
||||
working := parseCompositionDocument(t, "defaults", "collections: {north: {records: [{id: default}]}, south: {records: [{id: default}]}}\n")
|
||||
index := new(mappingIndex)
|
||||
for _, application := range composed.applications {
|
||||
applyHistoryApplication(&working, application, index)
|
||||
}
|
||||
for path, want := range map[string][]string{
|
||||
"/records": {"a", "b"},
|
||||
"/other": {"x", "y"},
|
||||
"/collections/north/records": {"a", "b"},
|
||||
"/collections/south/records": {"x", "y"},
|
||||
} {
|
||||
sequence, present := documentAtPath(working, mustParsePath(t, path))
|
||||
if !present || sequence.Kind != document.Sequence || len(sequence.Sequence) != len(want) {
|
||||
@@ -53,14 +54,14 @@ func TestSequenceHistoryReplaysAppendAtAssignedIndexes(t *testing.T) {
|
||||
application := composed.applications[1]
|
||||
cloned := cloneHistoryApplications(composed.applications)
|
||||
cloned[1].sequences[0].path.segments[0].key = "mutated"
|
||||
if composed.applications[1].sequences[0].path.String() != "/records" {
|
||||
if composed.applications[1].sequences[0].path.String() != "/collections/north/records" {
|
||||
t.Fatal("cloned sequence history path aliases its source")
|
||||
}
|
||||
addedPath := Keys("records").Index(1).Key("value")
|
||||
addedPath := Keys("collections", "north", "records").Index(1).Key("value")
|
||||
if operation, relevant := applicationOperationPath(application, addedPath, nil); !relevant || operation.String() != addedPath.String() {
|
||||
t.Fatalf("appended value operation = %s, %v", operation.String(), relevant)
|
||||
}
|
||||
if _, relevant := applicationOperationPath(application, Keys("records").Index(0).Key("value"), nil); relevant {
|
||||
if _, relevant := applicationOperationPath(application, Keys("collections", "north", "records").Index(0).Key("value"), nil); relevant {
|
||||
t.Fatal("later contribution was reported as changing an earlier record")
|
||||
}
|
||||
origin := historyApplicationOrigin(application, addedPath, nil)
|
||||
@@ -69,10 +70,10 @@ func TestSequenceHistoryReplaysAppendAtAssignedIndexes(t *testing.T) {
|
||||
}
|
||||
overlay := historyApplication{
|
||||
layer: LayerOverlay,
|
||||
value: parseCompositionDocument(t, "overlay", "records: []\n"),
|
||||
value: parseCompositionDocument(t, "overlay", "collections: {north: {records: []}}\n"),
|
||||
}
|
||||
applyHistoryApplication(&working, overlay, index)
|
||||
replaced, present := documentAtPath(working, Keys("records"))
|
||||
replaced, present := documentAtPath(working, Keys("collections", "north", "records"))
|
||||
if !present || replaced.Kind != document.Sequence || len(replaced.Sequence) != 0 {
|
||||
t.Fatalf("ordinary later list replacement = %#v, %v", replaced, present)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user