Prepare resolution entry provenance view
This commit is contained in:
@@ -148,6 +148,89 @@ func TestMetadataQueriesReturnDetachedRecords(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestResolutionInputKeepsDetachedEntryMetadata(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
type configuration struct {
|
||||
Default string `yaml:"default"`
|
||||
Items []string `yaml:"items"`
|
||||
Values map[string]string `yaml:"values"`
|
||||
Nullable *string `yaml:"nullable"`
|
||||
}
|
||||
schema := mustSchemaFor[configuration](t)
|
||||
document := parseDocumentForDecode(t, "items: [first]\nvalues: {'0': key, 'a/b~': escaped}\nnullable: null\n")
|
||||
decoded, issues := decodeConfiguration(schema, reflect.ValueOf(configuration{Default: "retained"}), document)
|
||||
if len(issues) != 0 {
|
||||
t.Fatalf("decode issues = %#v", issues)
|
||||
}
|
||||
metadata := metadataFromDecoded(decoded)
|
||||
input := newResolutionInput(metadata, decoded.final, []SourceInfo{{
|
||||
ID: "source-1", Label: "decode.yml", Layer: LayerBase,
|
||||
ImportedFrom: &Location{SourceID: "parent", Line: 1, Column: 1},
|
||||
}})
|
||||
|
||||
parsedItem, err := ParsePath("/items/0")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
parsedKey, err := ParsePath("/values/0")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for _, path := range []Path{Path{}, Keys("default"), Keys("nullable"), parsedItem, parsedKey, Keys("values", "a/b~")} {
|
||||
if _, ok := input.lookup(path); !ok {
|
||||
t.Fatalf("entry path %s is missing", path)
|
||||
}
|
||||
}
|
||||
defaultInfo, _ := input.lookup(Keys("default"))
|
||||
nullInfo, _ := input.lookup(Keys("nullable"))
|
||||
if defaultInfo.Explicit || !nullInfo.Explicit || !nullInfo.Null {
|
||||
t.Fatalf("default = %#v, nullable = %#v", defaultInfo, nullInfo)
|
||||
}
|
||||
for _, path := range []Path{
|
||||
Keys("default", "child"),
|
||||
Keys("items", "0"),
|
||||
Keys("values").Index(0),
|
||||
Keys("items").Index(1),
|
||||
} {
|
||||
if _, ok := input.lookup(path); ok {
|
||||
t.Fatalf("entry lookup accepted %s", path)
|
||||
}
|
||||
}
|
||||
|
||||
item, _ := input.lookup(parsedItem)
|
||||
item.Origin.Locations[0].SourceID = "mutated"
|
||||
source, ok := input.source("source-1")
|
||||
if !ok {
|
||||
t.Fatal("source is missing")
|
||||
}
|
||||
source.ImportedFrom.SourceID = "mutated"
|
||||
|
||||
configurationAtEntry := decoded.value.Interface().(configuration)
|
||||
resolved := runResolution(&configurationAtEntry, func(value *configuration, resolution *Resolution) error {
|
||||
value.Items[0] = "normalized"
|
||||
resolution.Record(Keys("items"), ChangeNormalization, "normalized item")
|
||||
return nil
|
||||
}, schema, decoded, document)
|
||||
if len(resolved.diagnostics) != 0 {
|
||||
t.Fatalf("resolution diagnostics = %#v", resolved.diagnostics)
|
||||
}
|
||||
applyResolutionMetadata(&metadata, resolved)
|
||||
metadata.effectivePaths = effectivePathIndex(resolved.final)
|
||||
|
||||
again, ok := input.lookup(parsedItem)
|
||||
if !ok || again.Origin.Locations[0].SourceID != "source-1" || again.Origin.Operation != "" {
|
||||
t.Fatalf("entry metadata changed after resolution = %#v, %v", again, ok)
|
||||
}
|
||||
againSource, ok := input.source("source-1")
|
||||
if !ok || againSource.ImportedFrom == nil || againSource.ImportedFrom.SourceID != "parent" {
|
||||
t.Fatalf("entry source changed = %#v, %v", againSource, ok)
|
||||
}
|
||||
if _, ok := input.source(""); ok {
|
||||
t.Fatal("empty source identity resolved")
|
||||
}
|
||||
}
|
||||
|
||||
func TestQueriesRespectActualHistoricalAndEffectiveContainers(t *testing.T) {
|
||||
result, err := Load[map[string]any](Bytes("base", []byte("items: [1]\nm: {'0': 2}\nx: 3\nretired: {child: 4}\n")), Options[map[string]any]{Overrides: []Override{{Path: Keys("retired"), Value: "removed", Flag: "--retired"}}})
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user