Added more tests to ensure correct coverage.

Signed-off-by: Dave Shanley <dave@quobix.com>
This commit is contained in:
Dave Shanley
2023-07-18 14:29:00 -04:00
committed by quobix
parent 0fbcb81015
commit d17ae1d610
3 changed files with 149 additions and 43 deletions

View File

@@ -145,7 +145,7 @@ func CheckPropertyAdditionOrRemoval[T any](l, r *yaml.Node,
//
// The Change is then added to the slice of []Change[T] instances provided as a pointer.
func CheckForRemoval[T any](l, r *yaml.Node, label string, changes *[]*Change, breaking bool, orig, new T) {
if l != nil && l.Value != "" && (r == nil || r.Value == "") {
if l != nil && l.Value != "" && (r == nil || r.Value == "" && !utils.IsNodeArray(r) && !utils.IsNodeMap(r)) {
CreateChange(changes, PropertyRemoved, label, l, r, breaking, orig, new)
return
}
@@ -163,7 +163,7 @@ func CheckForRemoval[T any](l, r *yaml.Node, label string, changes *[]*Change, b
func CheckForAddition[T any](l, r *yaml.Node, label string, changes *[]*Change, breaking bool, orig, new T) {
if (l == nil || l.Value == "") && (r != nil && (r.Value != "" || utils.IsNodeArray(r)) || utils.IsNodeMap(r)) {
if r != nil {
if l != nil && len(l.Content) < len(r.Content) {
if l != nil && (len(l.Content) < len(r.Content)) && len(l.Content) <= 0 {
CreateChange(changes, PropertyAdded, label, l, r, breaking, orig, new)
}
if l == nil {
@@ -188,10 +188,18 @@ func CheckForModification[T any](l, r *yaml.Node, label string, changes *[]*Chan
CreateChange(changes, Modified, label, l, r, breaking, orig, new)
return
}
if l != nil && !utils.IsNodeArray(l) && r != nil && utils.IsNodeArray(r) {
CreateChange(changes, Modified, label, l, r, breaking, orig, new)
return
}
if l != nil && utils.IsNodeMap(l) && r != nil && !utils.IsNodeMap(r) {
CreateChange(changes, Modified, label, l, r, breaking, orig, new)
return
}
if l != nil && !utils.IsNodeMap(l) && r != nil && utils.IsNodeMap(r) {
CreateChange(changes, Modified, label, l, r, breaking, orig, new)
return
}
if l != nil && utils.IsNodeArray(l) && r != nil && utils.IsNodeArray(r) {
if len(l.Content) != len(r.Content) {
CreateChange(changes, Modified, label, l, r, breaking, orig, new)
@@ -209,11 +217,7 @@ func CheckForModification[T any](l, r *yaml.Node, label string, changes *[]*Chan
return
}
if l != nil && utils.IsNodeMap(l) && r != nil && utils.IsNodeMap(r) {
if len(l.Content) != len(r.Content) {
CreateChange(changes, Modified, label, l, r, breaking, orig, new)
return
}
// there is no way to know how to compare the content of the array, without
// there is no way to know how to compare the content of the map, without
// rendering the yaml.Node to a string and comparing the string.
leftBytes, _ := yaml.Marshal(l)
rightBytes, _ := yaml.Marshal(r)