chore(schema/testing): upgrade to go 1.23 iterators (#21282)

Co-authored-by: Julien Robert <julien@rbrt.fr>
This commit is contained in:
Aaron Craelius 2024-08-15 16:58:58 -04:00 committed by GitHub
parent 858ec2fcb8
commit 0f39b4e491
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 16 additions and 23 deletions

View File

@ -27,21 +27,21 @@ func DiffAppStates(expected, actual view.AppState) string {
res += fmt.Sprintf("MODULE COUNT ERROR: expected %d, got %d\n", expectNumModules, actualNumModules)
}
expected.Modules(func(expectedMod view.ModuleState, err error) bool {
for expectedMod, err := range expected.Modules {
if err != nil {
res += fmt.Sprintf("ERROR getting expected module: %s\n", err)
return true
continue
}
moduleName := expectedMod.ModuleName()
actualMod, err := actual.GetModule(moduleName)
if err != nil {
res += fmt.Sprintf("ERROR getting actual module: %s\n", err)
return true
continue
}
if actualMod == nil {
res += fmt.Sprintf("Module %s: actual module NOT FOUND\n", moduleName)
return true
continue
}
diff := DiffModuleStates(expectedMod, actualMod)
@ -49,9 +49,7 @@ func DiffAppStates(expected, actual view.AppState) string {
res += "Module " + moduleName + "\n"
res += indentAllLines(diff)
}
return true
})
}
return res
}

View File

@ -27,21 +27,21 @@ func DiffModuleStates(expected, actual view.ModuleState) string {
res += fmt.Sprintf("OBJECT COLLECTION COUNT ERROR: expected %d, got %d\n", expectedNumObjectCollections, actualNumObjectCollections)
}
expected.ObjectCollections(func(expectedColl view.ObjectCollection, err error) bool {
for expectedColl, err := range expected.ObjectCollections {
if err != nil {
res += fmt.Sprintf("ERROR getting expected object collection: %s\n", err)
return true
continue
}
objTypeName := expectedColl.ObjectType().Name
actualColl, err := actual.GetObjectCollection(objTypeName)
if err != nil {
res += fmt.Sprintf("ERROR getting actual object collection: %s\n", err)
return true
continue
}
if actualColl == nil {
res += fmt.Sprintf("Object Collection %s: actuall collection NOT FOUND\n", objTypeName)
return true
continue
}
diff := DiffObjectCollections(expectedColl, actualColl)
@ -49,9 +49,7 @@ func DiffModuleStates(expected, actual view.ModuleState) string {
res += "Object Collection " + objTypeName + "\n"
res += indentAllLines(diff)
}
return true
})
}
return res
}

View File

@ -4,7 +4,6 @@ import (
"fmt"
"strings"
"cosmossdk.io/schema"
schematesting "cosmossdk.io/schema/testing"
"cosmossdk.io/schema/view"
)
@ -30,21 +29,21 @@ func DiffObjectCollections(expected, actual view.ObjectCollection) string {
res += fmt.Sprintf("OBJECT COUNT ERROR: expected %d, got %d\n", expectedNumObjects, actualNumObjects)
}
expected.AllState(func(expectedUpdate schema.ObjectUpdate, err error) bool {
for expectedUpdate, err := range expected.AllState {
if err != nil {
res += fmt.Sprintf("ERROR getting expected object: %s\n", err)
return true
continue
}
keyStr := fmtObjectKey(expected.ObjectType(), expectedUpdate.Key)
actualUpdate, found, err := actual.GetObject(expectedUpdate.Key)
if err != nil {
res += fmt.Sprintf("Object %s: ERROR: %v\n", keyStr, err)
return true
continue
}
if !found {
res += fmt.Sprintf("Object %s: NOT FOUND\n", keyStr)
return true
continue
}
if expectedUpdate.Delete != actualUpdate.Delete {
@ -52,7 +51,7 @@ func DiffObjectCollections(expected, actual view.ObjectCollection) string {
}
if expectedUpdate.Delete {
return true
continue
}
valueDiff := schematesting.DiffObjectValues(expected.ObjectType().ValueFields, expectedUpdate.Value, actualUpdate.Value)
@ -62,9 +61,7 @@ func DiffObjectCollections(expected, actual view.ObjectCollection) string {
res += "\n"
res += indentAllLines(valueDiff)
}
return true
})
}
return res
}