43 lines
1.6 KiB
Go
43 lines
1.6 KiB
Go
package engine
|
|
|
|
import "testing"
|
|
|
|
func TestMovedRemovedFieldHasConsistentHistory(t *testing.T) {
|
|
type config struct {
|
|
Items []map[string]any `yaml:"items"`
|
|
}
|
|
definition := DefinitionWithSequenceIdentityRegistrations(Definition[config]{
|
|
Resolve: func(value *config, r *Resolution) error {
|
|
delete(value.Items[0], "extra")
|
|
value.Items[0], value.Items[1] = value.Items[1], value.Items[0]
|
|
r.RecordNormalization(Keys("items"), "remove field and reorder")
|
|
return nil
|
|
},
|
|
}, []SequenceIdentityRegistrationInput{{ExactPath: pathPointer(Keys("items")), IdentityFields: []string{"id"}}})
|
|
result, err := testLoad(Bytes("records", []byte("items: [{id: a, extra: own}, {id: b}]\n")), Options[config]{Definition: definition})
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
path := Keys("items").Index(1).Key("extra")
|
|
if _, found := result.Metadata().Lookup(path); found {
|
|
t.Fatal("removed field is effective")
|
|
}
|
|
explanation, found := result.Inspection.Explain(path)
|
|
if !found || len(explanation.History) != 2 {
|
|
t.Fatalf("explanation = %#v, %t", explanation, found)
|
|
}
|
|
history := result.Metadata().History(path)
|
|
if len(history) != 2 || history[0].Origin.Layer != LayerMain || history[1].Origin.Operation != ChangeNormalization {
|
|
t.Fatalf("metadata history = %#v", history)
|
|
}
|
|
last := explanation.History[1]
|
|
if last.Before.YAML != "own\n" || last.After.Present {
|
|
t.Fatalf("removal = %#v", last)
|
|
}
|
|
for _, unknown := range []Path{Keys("items", "1", "extra"), Keys("items").Index(1).Key("unknown")} {
|
|
if history := result.Metadata().History(unknown); len(history) != 0 {
|
|
t.Fatalf("unexpected history for %s: %#v", unknown.String(), history)
|
|
}
|
|
}
|
|
}
|