fix: fixed tests after merge

This commit is contained in:
Tristan Cartledge
2023-11-27 17:05:37 +00:00
parent 2de65e4ca0
commit 785824a271
23 changed files with 194 additions and 220 deletions

View File

@@ -26,8 +26,8 @@ var changeMutex sync.Mutex
// CreateChange is a generic function that will create a Change of type T, populate all properties if set, and then
// add a pointer to Change[T] in the slice of Change pointers provided
func CreateChange(changes *[]*Change, changeType int, property string, leftValueNode, rightValueNode *yaml.Node,
breaking bool, originalObject, newObject any) *[]*Change {
breaking bool, originalObject, newObject any,
) *[]*Change {
// create a new context for the left and right nodes.
ctx := CreateContext(leftValueNode, rightValueNode)
c := &Change{
@@ -71,7 +71,8 @@ func CreateContext(l, r *yaml.Node) *ChangeContext {
}
func FlattenLowLevelMap[T any](
lowMap map[low.KeyReference[string]]low.ValueReference[T]) map[string]*low.ValueReference[T] {
lowMap map[low.KeyReference[string]]low.ValueReference[T],
) map[string]*low.ValueReference[T] {
flat := make(map[string]*low.ValueReference[T])
for i := range lowMap {
l := lowMap[i]
@@ -80,6 +81,19 @@ func FlattenLowLevelMap[T any](
return flat
}
func FlattenLowLevelOrderedMap[T any](
lowMap orderedmap.Map[low.KeyReference[string], low.ValueReference[T]],
) map[string]*low.ValueReference[T] {
flat := make(map[string]*low.ValueReference[T])
for pair := orderedmap.First(lowMap); pair != nil; pair = pair.Next() {
k := pair.Key()
l := pair.Value()
flat[k.Value] = &l
}
return flat
}
// CountBreakingChanges counts the number of changes in a slice that are breaking
func CountBreakingChanges(changes []*Change) int {
b := 0
@@ -99,7 +113,8 @@ func CountBreakingChanges(changes []*Change) int {
// properties like descriptions, summaries and other non-binding values, so a breakingRemove value can be tuned for
// these circumstances.
func CheckForObjectAdditionOrRemoval[T any](l, r map[string]*low.ValueReference[T], label string, changes *[]*Change,
breakingAdd, breakingRemove bool) {
breakingAdd, breakingRemove bool,
) {
var left, right T
if CheckSpecificObjectRemoved(l, r, label) {
left = l[label].GetValue()
@@ -129,7 +144,6 @@ func CheckSpecificObjectAdded[T any](l, r map[string]*T, label string) bool {
// CheckPropertyAdditionOrRemoval
// CheckForModification
func CheckProperties(properties []*PropertyCheck) {
// todo: make this async to really speed things up.
for _, n := range properties {
CheckPropertyAdditionOrRemoval(n.LeftNode, n.RightNode, n.Label, n.Changes, n.Breaking, n.Original, n.New)
@@ -139,7 +153,8 @@ func CheckProperties(properties []*PropertyCheck) {
// CheckPropertyAdditionOrRemoval will run both CheckForRemoval (first) and CheckForAddition (second)
func CheckPropertyAdditionOrRemoval[T any](l, r *yaml.Node,
label string, changes *[]*Change, breaking bool, orig, new T) {
label string, changes *[]*Change, breaking bool, orig, new T,
) {
CheckForRemoval[T](l, r, label, changes, breaking, orig, new)
CheckForAddition[T](l, r, label, changes, breaking, orig, new)
}
@@ -238,12 +253,14 @@ func CheckForModification[T any](l, r *yaml.Node, label string, changes *[]*Chan
// CheckMapForChanges checks a left and right low level map for any additions, subtractions or modifications to
// values. The compareFunc argument should reference the correct comparison function for the generic type.
func CheckMapForChanges[T any, R any](expLeft, expRight orderedmap.Map[low.KeyReference[string], low.ValueReference[T]],
changes *[]*Change, label string, compareFunc func(l, r T) R) map[string]R {
changes *[]*Change, label string, compareFunc func(l, r T) R,
) map[string]R {
return CheckMapForChangesWithComp(expLeft, expRight, changes, label, compareFunc, true)
}
func CheckMapForAdditionRemoval[T any](expLeft, expRight orderedmap.Map[low.KeyReference[string], low.ValueReference[T]],
changes *[]*Change, label string) any {
changes *[]*Change, label string,
) any {
// do nothing
doNothing := func(l, r T) any {
return nil
@@ -266,8 +283,8 @@ func CheckMapForAdditionRemoval[T any](expLeft, expRight orderedmap.Map[low.KeyR
// values. The compareFunc argument should reference the correct comparison function for the generic type. The compare
// bit determines if the comparison should be run or not.
func CheckMapForChangesWithComp[T any, R any](expLeft, expRight orderedmap.Map[low.KeyReference[string], low.ValueReference[T]],
changes *[]*Change, label string, compareFunc func(l, r T) R, compare bool) map[string]R {
changes *[]*Change, label string, compareFunc func(l, r T) R, compare bool,
) map[string]R {
// stop concurrent threads screwing up changes.
var chLock sync.Mutex
@@ -331,7 +348,7 @@ func CheckMapForChangesWithComp[T any, R any](expLeft, expRight orderedmap.Map[l
go checkLeft(k, doneChan, lHashes, rHashes, lValues, rValues)
}
//check right example hashes
// check right example hashes
for k := range rHashes {
count++
go checkRightValue(k, doneChan, lHashes, rValues, changes, label, &chLock)
@@ -349,8 +366,8 @@ func CheckMapForChangesWithComp[T any, R any](expLeft, expRight orderedmap.Map[l
}
func checkRightValue[T any](k string, doneChan chan bool, f map[string]string, p map[string]low.ValueReference[T],
changes *[]*Change, label string, lock *sync.Mutex) {
changes *[]*Change, label string, lock *sync.Mutex,
) {
lhash := f[k]
if lhash == "" {
lock.Lock()
@@ -367,7 +384,8 @@ func checkRightValue[T any](k string, doneChan chan bool, f map[string]string, p
// ExtractStringValueSliceChanges will compare two low level string slices for changes.
func ExtractStringValueSliceChanges(lParam, rParam []low.ValueReference[string],
changes *[]*Change, label string, breaking bool) {
changes *[]*Change, label string, breaking bool,
) {
lKeys := make([]string, len(lParam))
rKeys := make([]string, len(rParam))
lValues := make(map[string]low.ValueReference[string])
@@ -404,7 +422,8 @@ func ExtractStringValueSliceChanges(lParam, rParam []low.ValueReference[string],
// ExtractRawValueSliceChanges will compare two low level interface{} slices for changes.
func ExtractRawValueSliceChanges(lParam, rParam []low.ValueReference[any],
changes *[]*Change, label string, breaking bool) {
changes *[]*Change, label string, breaking bool,
) {
lKeys := make([]string, len(lParam))
rKeys := make([]string, len(rParam))
lValues := make(map[string]low.ValueReference[any])