Replay matched record input history at entry positions
This commit is contained in:
@@ -303,6 +303,23 @@ func TestRegisteredResolutionHistoryFollowsMatchedSource(t *testing.T) {
|
||||
if !found {
|
||||
t.Errorf("missing source line %d in %#v", check.line, history)
|
||||
}
|
||||
explanation, ok := result.Inspection.Explain(path)
|
||||
if !ok {
|
||||
t.Fatalf("missing explanation for %s", path.String())
|
||||
}
|
||||
want := "second\n"
|
||||
if check.index == 1 {
|
||||
want = "first\n"
|
||||
}
|
||||
foundValue := false
|
||||
for _, change := range explanation.History {
|
||||
if change.Origin.Layer == LayerMain && change.After.YAML == want {
|
||||
foundValue = true
|
||||
}
|
||||
}
|
||||
if !foundValue {
|
||||
t.Errorf("missing matched input %q in %#v", want, explanation.History)
|
||||
}
|
||||
}
|
||||
for _, change := range result.Metadata().History(Keys("items").Index(2).Key("value")) {
|
||||
if change.Origin.Layer == LayerMain {
|
||||
@@ -310,3 +327,66 @@ func TestRegisteredResolutionHistoryFollowsMatchedSource(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestMovedRecordExplanationIncludesInheritedValue(t *testing.T) {
|
||||
type item struct {
|
||||
ID string `yaml:"id"`
|
||||
Value string `yaml:"value"`
|
||||
}
|
||||
type config struct {
|
||||
Items []item `yaml:"items"`
|
||||
}
|
||||
definition := DefinitionWithSequenceIdentityRegistrations(Definition[config]{Resolve: func(value *config, r *Resolution) error {
|
||||
value.Items[0], value.Items[1] = value.Items[1], value.Items[0]
|
||||
r.RecordNormalization(Keys("items"), "reorder")
|
||||
return nil
|
||||
}}, []SequenceIdentityRegistrationInput{{ExactPath: pathPointer(Keys("items")), IdentityFields: []string{"id"}}})
|
||||
result, err := testLoad(Bytes("records", []byte("items: [{id: parent, value: inherited}, {id: child, extends: {id: parent}}]\n")), Options[config]{Definition: definition})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
explanation, ok := result.Inspection.Explain(Keys("items").Index(0).Key("value"))
|
||||
if !ok {
|
||||
t.Fatal("missing explanation")
|
||||
}
|
||||
found := false
|
||||
for _, change := range explanation.History {
|
||||
if change.After.YAML == "inherited\n" {
|
||||
found = true
|
||||
}
|
||||
}
|
||||
if !found {
|
||||
t.Fatalf("inherited history = %#v", explanation.History)
|
||||
}
|
||||
}
|
||||
|
||||
func TestMovedRecordExplanationIncludesCLIValue(t *testing.T) {
|
||||
type item struct {
|
||||
ID string `yaml:"id"`
|
||||
Value string `yaml:"value"`
|
||||
}
|
||||
type config struct {
|
||||
Items []item `yaml:"items"`
|
||||
}
|
||||
definition := DefinitionWithSequenceIdentityRegistrations(Definition[config]{Resolve: func(value *config, r *Resolution) error {
|
||||
value.Items[0], value.Items[1] = value.Items[1], value.Items[0]
|
||||
r.RecordNormalization(Keys("items"), "reorder")
|
||||
return nil
|
||||
}}, []SequenceIdentityRegistrationInput{{ExactPath: pathPointer(Keys("items")), IdentityFields: []string{"id"}}})
|
||||
result, err := testLoad(NoSource(), Options[config]{Definition: definition, Overrides: []Override{{
|
||||
Path: Keys("items"), Flag: "--items", Value: []any{map[string]any{"id": "a", "value": "first"}, map[string]any{"id": "b", "value": "second"}},
|
||||
}}})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
explanation, ok := result.Inspection.Explain(Keys("items").Index(1).Key("value"))
|
||||
if !ok {
|
||||
t.Fatal("missing explanation")
|
||||
}
|
||||
for _, change := range explanation.History {
|
||||
if change.Origin.Layer == LayerCLI && change.After.YAML == "first\n" {
|
||||
return
|
||||
}
|
||||
}
|
||||
t.Fatalf("CLI history = %#v", explanation.History)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user