Index sequence assembly and history lookups
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package engine
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"reflect"
|
||||
"strings"
|
||||
"testing"
|
||||
@@ -8,6 +9,52 @@ import (
|
||||
"gitea.maximumdirect.net/eric/ConfigKit/internal/document"
|
||||
)
|
||||
|
||||
func TestComposeWideRegisteredCollectionsPreservesEvidenceAndReplay(t *testing.T) {
|
||||
policy := sequencePolicy{identityFields: make(map[string]string)}
|
||||
var inputs []*document.Node
|
||||
for source := 0; source < 3; source++ {
|
||||
var text strings.Builder
|
||||
for collection := 0; collection < 128; collection++ {
|
||||
key := fmt.Sprintf("records%d", collection)
|
||||
policy.identityFields[Keys(key).String()] = "id"
|
||||
fmt.Fprintf(&text, "%s: [{id: source%d}]\n", key, source)
|
||||
}
|
||||
inputs = append(inputs, parseCompositionDocument(t, fmt.Sprintf("source-%d", source), text.String()))
|
||||
}
|
||||
composed, diagnostics := composeDocumentsWithPolicy(policy, inputs...)
|
||||
if len(diagnostics) != 0 {
|
||||
t.Fatal(diagnostics)
|
||||
}
|
||||
working := &document.Node{Kind: document.Mapping}
|
||||
for _, application := range composed.applications {
|
||||
applyHistoryApplication(&working, application, new(mappingIndex))
|
||||
}
|
||||
if !configurationValuesEqual(working, composed.root) {
|
||||
t.Fatal("wide registered collections replay differs from assembly")
|
||||
}
|
||||
for collection := 0; collection < 128; collection++ {
|
||||
path := Keys(fmt.Sprintf("records%d", collection)).Index(2).Key("id")
|
||||
origin := composed.origins[path.String()]
|
||||
if len(origin.Locations) != 1 || origin.Locations[0].SourceID != "source-2" {
|
||||
t.Fatalf("shifted origin at %s = %#v", path.String(), origin)
|
||||
}
|
||||
local, ok := historyApplicationLocalPath(composed.applications[2], path)
|
||||
if !ok || local.String() != Keys(fmt.Sprintf("records%d", collection)).Index(0).Key("id").String() {
|
||||
t.Fatal("wide local path projection failed")
|
||||
}
|
||||
}
|
||||
clone := cloneComposedDocument(composed)
|
||||
for _, original := range composed.applications[0].sequences {
|
||||
pointer := original.path.String()
|
||||
copy := clone.applications[0].sequencesByPath[pointer]
|
||||
copy.path.segments[0].key = "changed"
|
||||
if composed.applications[0].sequencesByPath[pointer].path.String() != pointer {
|
||||
t.Fatal("history path index aliases cloned state")
|
||||
}
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
func TestComposeDocumentsJoinsDisjointMappingsAndTracksClaims(t *testing.T) {
|
||||
base := parseCompositionDocument(t, "source-1", `services:
|
||||
api:
|
||||
|
||||
Reference in New Issue
Block a user