Strengthen composition and import selection tests
This commit is contained in:
@@ -43,9 +43,10 @@ func FuzzCompositionAndOverlay(f *testing.F) {
|
||||
if differences := compareConfigurationValues(composed.root, reversed.root); len(differences) != 0 {
|
||||
t.Fatalf("composition order changed effective values: %#v", differences)
|
||||
}
|
||||
composed.root.Mapping = append(composed.root.Mapping, document.Entry{Key: "fuzz-detachment"})
|
||||
if !reflect.DeepEqual(left, leftBefore) || !reflect.DeepEqual(right, rightBefore) {
|
||||
t.Fatal("composition result aliases an input document")
|
||||
if mutateExistingDocumentDescendant(composed.root) {
|
||||
if !reflect.DeepEqual(left, leftBefore) || !reflect.DeepEqual(right, rightBefore) {
|
||||
t.Fatal("composition result aliases an input document")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -60,9 +61,41 @@ func FuzzCompositionAndOverlay(f *testing.F) {
|
||||
if !reflect.DeepEqual(left, leftBefore) || !reflect.DeepEqual(right, rightBefore) {
|
||||
t.Fatal("overlay mutated an input document")
|
||||
}
|
||||
overlaid.root.Mapping = append(overlaid.root.Mapping, document.Entry{Key: "fuzz-detachment"})
|
||||
if !reflect.DeepEqual(left, leftBefore) || !reflect.DeepEqual(right, rightBefore) {
|
||||
t.Fatal("overlay result aliases an input document")
|
||||
if mutateExistingDocumentDescendant(overlaid.root) {
|
||||
if !reflect.DeepEqual(left, leftBefore) || !reflect.DeepEqual(right, rightBefore) {
|
||||
t.Fatal("overlay result aliases an input document")
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func mutateExistingDocumentDescendant(node *document.Node) bool {
|
||||
if node == nil {
|
||||
return false
|
||||
}
|
||||
// Empty containers have no existing element for the alias probe.
|
||||
switch node.Kind {
|
||||
case document.Mapping:
|
||||
if len(node.Mapping) == 0 {
|
||||
return false
|
||||
}
|
||||
entry := &node.Mapping[0]
|
||||
if mutateExistingDocumentDescendant(entry.Value) {
|
||||
return true
|
||||
}
|
||||
entry.Key += "-fuzz-detachment"
|
||||
return true
|
||||
case document.Sequence:
|
||||
if len(node.Sequence) == 0 {
|
||||
return false
|
||||
}
|
||||
if mutateExistingDocumentDescendant(node.Sequence[0]) {
|
||||
return true
|
||||
}
|
||||
node.Sequence[0].Text += "fuzz-detachment"
|
||||
return true
|
||||
default:
|
||||
node.Text += "fuzz-detachment"
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user