Index resolution metadata updates
This commit is contained in:
@@ -71,3 +71,48 @@ func TestDocumentLookupMatchesPathScan(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestApplyResolutionMetadataPreservesOverlappingDeltaOrder(t *testing.T) {
|
||||
oldOrigin := Origin{Layer: LayerBase}
|
||||
parentOrigin := Origin{Layer: LayerResolution, Operation: ChangeNormalization}
|
||||
childOrigin := Origin{Layer: LayerResolution, Operation: ChangeDerivedDefault}
|
||||
leaf := &document.Node{Kind: document.String, Text: "value"}
|
||||
final := &document.Node{Kind: document.Mapping, Mapping: []document.Entry{{
|
||||
Key: "group",
|
||||
Value: &document.Node{Kind: document.Mapping, Mapping: []document.Entry{{
|
||||
Key: "item",
|
||||
Value: &document.Node{Kind: document.Mapping, Mapping: []document.Entry{{Key: "leaf", Value: leaf}}},
|
||||
}}},
|
||||
}}}
|
||||
metadata := &Metadata{
|
||||
fields: map[string]FieldInfo{"/group/item/leaf": {Origin: oldOrigin}},
|
||||
history: make(map[string][]Change),
|
||||
}
|
||||
resolved := resolutionResult{
|
||||
final: final,
|
||||
deltas: []documentDelta{{path: Keys("group")}, {path: Keys("group", "item")}},
|
||||
snapshots: []resolutionSnapshot{
|
||||
{change: Change{Path: Keys("group"), Origin: parentOrigin}},
|
||||
{change: Change{Path: Keys("group", "item"), Origin: childOrigin}},
|
||||
},
|
||||
}
|
||||
|
||||
applyResolutionMetadata(metadata, resolved)
|
||||
|
||||
field := metadata.fields["/group/item/leaf"]
|
||||
if field.Origin.Operation != childOrigin.Operation {
|
||||
t.Fatalf("final leaf origin operation = %q, want %q", field.Origin.Operation, childOrigin.Operation)
|
||||
}
|
||||
changes := metadata.history["/group/item/leaf"]
|
||||
if len(changes) != 2 {
|
||||
t.Fatalf("leaf history has %d entries, want 2: %#v", len(changes), changes)
|
||||
}
|
||||
if changes[0].Origin.Operation != parentOrigin.Operation || changes[1].Origin.Operation != childOrigin.Operation {
|
||||
t.Fatalf("leaf history operations = %q, %q; want %q, %q", changes[0].Origin.Operation, changes[1].Origin.Operation, parentOrigin.Operation, childOrigin.Operation)
|
||||
}
|
||||
for index, change := range changes {
|
||||
if len(change.Previous) != 1 || change.Previous[0].Layer != oldOrigin.Layer {
|
||||
t.Errorf("leaf history[%d] Previous = %#v, want original origin", index, change.Previous)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user