engine: resources: Change Res API from Compare to Cmp

This will be done by refactoring the current method, to return an error
message instead of a boolean value. This will also update a typo on the
user res.
This commit is contained in:
Donald Bakong
2019-09-19 00:48:07 -04:00
committed by James Shubin
parent 89bdafacb8
commit fc1c631c98
12 changed files with 110 additions and 206 deletions

View File

@@ -506,34 +506,26 @@ func (obj *NetRes) CheckApply(apply bool) (bool, error) {
// Cmp compares two resources and returns an error if they are not equivalent.
func (obj *NetRes) Cmp(r engine.Res) error {
if !obj.Compare(r) {
return fmt.Errorf("did not compare")
}
return nil
}
// Compare two resources and return if they are equivalent.
func (obj *NetRes) Compare(r engine.Res) bool {
// we can only compare NetRes to others of the same resource kind
res, ok := r.(*NetRes)
if !ok {
return false
return fmt.Errorf("not a %s", obj.Kind())
}
if obj.State != res.State {
return false
return fmt.Errorf("the State differs")
}
if (obj.Addrs == nil) != (res.Addrs == nil) {
return false
return fmt.Errorf("the Addrs differ")
}
if err := util.SortedStrSliceCompare(obj.Addrs, res.Addrs); err != nil {
return false
return fmt.Errorf("the Addrs differ")
}
if obj.Gateway != res.Gateway {
return false
return fmt.Errorf("the Gateway differs")
}
return true
return nil
}
// NetUID is a unique resource identifier.