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:
committed by
James Shubin
parent
89bdafacb8
commit
fc1c631c98
@@ -751,45 +751,37 @@ func (obj *AwsEc2Res) CheckApply(apply bool) (bool, error) {
|
|||||||
|
|
||||||
// Cmp compares two resources and returns an error if they are not equivalent.
|
// Cmp compares two resources and returns an error if they are not equivalent.
|
||||||
func (obj *AwsEc2Res) Cmp(r engine.Res) error {
|
func (obj *AwsEc2Res) 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 *AwsEc2Res) Compare(r engine.Res) bool {
|
|
||||||
// we can only compare AwsEc2Res to others of the same resource kind
|
// we can only compare AwsEc2Res to others of the same resource kind
|
||||||
res, ok := r.(*AwsEc2Res)
|
res, ok := r.(*AwsEc2Res)
|
||||||
if !ok {
|
if !ok {
|
||||||
return false
|
return fmt.Errorf("not a %s", obj.Kind())
|
||||||
}
|
}
|
||||||
|
|
||||||
if obj.State != res.State {
|
if obj.State != res.State {
|
||||||
return false
|
return fmt.Errorf("the State differs")
|
||||||
}
|
}
|
||||||
if obj.Region != res.Region {
|
if obj.Region != res.Region {
|
||||||
return false
|
return fmt.Errorf("the Region differs")
|
||||||
}
|
}
|
||||||
if obj.Type != res.Type {
|
if obj.Type != res.Type {
|
||||||
return false
|
return fmt.Errorf("the Type differs")
|
||||||
}
|
}
|
||||||
if obj.ImageID != res.ImageID {
|
if obj.ImageID != res.ImageID {
|
||||||
return false
|
return fmt.Errorf("the ImageID differs")
|
||||||
}
|
}
|
||||||
if obj.WatchEndpoint != res.WatchEndpoint {
|
if obj.WatchEndpoint != res.WatchEndpoint {
|
||||||
return false
|
return fmt.Errorf("the WatchEndpoint differs")
|
||||||
}
|
}
|
||||||
if obj.WatchListenAddr != res.WatchListenAddr {
|
if obj.WatchListenAddr != res.WatchListenAddr {
|
||||||
return false
|
return fmt.Errorf("the WatchListenAddr differs")
|
||||||
}
|
}
|
||||||
if obj.ErrorOnMalformedPost != res.ErrorOnMalformedPost {
|
if obj.ErrorOnMalformedPost != res.ErrorOnMalformedPost {
|
||||||
return false
|
return fmt.Errorf("the ErrorOnMalformedPost differs")
|
||||||
}
|
}
|
||||||
if obj.UserData != res.UserData {
|
if obj.UserData != res.UserData {
|
||||||
return false
|
return fmt.Errorf("the UserData differs")
|
||||||
}
|
}
|
||||||
return true
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (obj *AwsEc2Res) prependName() string {
|
func (obj *AwsEc2Res) prependName() string {
|
||||||
|
|||||||
@@ -220,32 +220,24 @@ func (obj *GroupRes) CheckApply(apply bool) (bool, error) {
|
|||||||
|
|
||||||
// Cmp compares two resources and returns an error if they are not equivalent.
|
// Cmp compares two resources and returns an error if they are not equivalent.
|
||||||
func (obj *GroupRes) Cmp(r engine.Res) error {
|
func (obj *GroupRes) 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 *GroupRes) Compare(r engine.Res) bool {
|
|
||||||
// we can only compare GroupRes to others of the same resource kind
|
// we can only compare GroupRes to others of the same resource kind
|
||||||
res, ok := r.(*GroupRes)
|
res, ok := r.(*GroupRes)
|
||||||
if !ok {
|
if !ok {
|
||||||
return false
|
return fmt.Errorf("not a %s", obj.Kind())
|
||||||
}
|
}
|
||||||
|
|
||||||
if obj.State != res.State {
|
if obj.State != res.State {
|
||||||
return false
|
return fmt.Errorf("the State differs")
|
||||||
}
|
}
|
||||||
if (obj.GID == nil) != (res.GID == nil) {
|
if (obj.GID == nil) != (res.GID == nil) {
|
||||||
return false
|
return fmt.Errorf("the GID differs")
|
||||||
}
|
}
|
||||||
if obj.GID != nil && res.GID != nil {
|
if obj.GID != nil && res.GID != nil {
|
||||||
if *obj.GID != *res.GID {
|
if *obj.GID != *res.GID {
|
||||||
return false
|
return fmt.Errorf("the GID differs")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// GroupUID is the UID struct for GroupRes.
|
// GroupUID is the UID struct for GroupRes.
|
||||||
|
|||||||
@@ -219,31 +219,23 @@ func (obj *HostnameRes) CheckApply(apply bool) (bool, error) {
|
|||||||
|
|
||||||
// Cmp compares two resources and returns an error if they are not equivalent.
|
// Cmp compares two resources and returns an error if they are not equivalent.
|
||||||
func (obj *HostnameRes) Cmp(r engine.Res) error {
|
func (obj *HostnameRes) 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 *HostnameRes) Compare(r engine.Res) bool {
|
|
||||||
// we can only compare HostnameRes to others of the same resource kind
|
// we can only compare HostnameRes to others of the same resource kind
|
||||||
res, ok := r.(*HostnameRes)
|
res, ok := r.(*HostnameRes)
|
||||||
if !ok {
|
if !ok {
|
||||||
return false
|
return fmt.Errorf("not a %s", obj.Kind())
|
||||||
}
|
}
|
||||||
|
|
||||||
if obj.PrettyHostname != res.PrettyHostname {
|
if obj.PrettyHostname != res.PrettyHostname {
|
||||||
return false
|
return fmt.Errorf("the PrettyHostname differs")
|
||||||
}
|
}
|
||||||
if obj.StaticHostname != res.StaticHostname {
|
if obj.StaticHostname != res.StaticHostname {
|
||||||
return false
|
return fmt.Errorf("the StaticHostname differs")
|
||||||
}
|
}
|
||||||
if obj.TransientHostname != res.TransientHostname {
|
if obj.TransientHostname != res.TransientHostname {
|
||||||
return false
|
return fmt.Errorf("the TransientHostname differs")
|
||||||
}
|
}
|
||||||
|
|
||||||
return true
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// HostnameUID is the UID struct for HostnameRes.
|
// HostnameUID is the UID struct for HostnameRes.
|
||||||
|
|||||||
@@ -200,36 +200,28 @@ func (obj *MsgRes) CheckApply(apply bool) (bool, error) {
|
|||||||
|
|
||||||
// Cmp compares two resources and returns an error if they are not equivalent.
|
// Cmp compares two resources and returns an error if they are not equivalent.
|
||||||
func (obj *MsgRes) Cmp(r engine.Res) error {
|
func (obj *MsgRes) 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 *MsgRes) Compare(r engine.Res) bool {
|
|
||||||
// we can only compare MsgRes to others of the same resource kind
|
// we can only compare MsgRes to others of the same resource kind
|
||||||
res, ok := r.(*MsgRes)
|
res, ok := r.(*MsgRes)
|
||||||
if !ok {
|
if !ok {
|
||||||
return false
|
return fmt.Errorf("not a %s", obj.Kind())
|
||||||
}
|
}
|
||||||
|
|
||||||
if obj.Body != res.Body {
|
if obj.Body != res.Body {
|
||||||
return false
|
return fmt.Errorf("the Body differs")
|
||||||
}
|
}
|
||||||
if obj.Priority != res.Priority {
|
if obj.Priority != res.Priority {
|
||||||
return false
|
return fmt.Errorf("the Priority differs")
|
||||||
}
|
}
|
||||||
if len(obj.Fields) != len(res.Fields) {
|
if len(obj.Fields) != len(res.Fields) {
|
||||||
return false
|
return fmt.Errorf("the length of Fields differs")
|
||||||
}
|
}
|
||||||
for field, value := range obj.Fields {
|
for field, value := range obj.Fields {
|
||||||
if res.Fields[field] != value {
|
if res.Fields[field] != value {
|
||||||
return false
|
return fmt.Errorf("the Fields differ")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return true
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// MsgUID is a unique representation for a MsgRes object.
|
// MsgUID is a unique representation for a MsgRes object.
|
||||||
|
|||||||
@@ -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.
|
// Cmp compares two resources and returns an error if they are not equivalent.
|
||||||
func (obj *NetRes) Cmp(r engine.Res) error {
|
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
|
// we can only compare NetRes to others of the same resource kind
|
||||||
res, ok := r.(*NetRes)
|
res, ok := r.(*NetRes)
|
||||||
if !ok {
|
if !ok {
|
||||||
return false
|
return fmt.Errorf("not a %s", obj.Kind())
|
||||||
}
|
}
|
||||||
|
|
||||||
if obj.State != res.State {
|
if obj.State != res.State {
|
||||||
return false
|
return fmt.Errorf("the State differs")
|
||||||
}
|
}
|
||||||
if (obj.Addrs == nil) != (res.Addrs == nil) {
|
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 {
|
if err := util.SortedStrSliceCompare(obj.Addrs, res.Addrs); err != nil {
|
||||||
return false
|
return fmt.Errorf("the Addrs differ")
|
||||||
}
|
}
|
||||||
if obj.Gateway != res.Gateway {
|
if obj.Gateway != res.Gateway {
|
||||||
return false
|
return fmt.Errorf("the Gateway differs")
|
||||||
}
|
}
|
||||||
|
|
||||||
return true
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// NetUID is a unique resource identifier.
|
// NetUID is a unique resource identifier.
|
||||||
|
|||||||
@@ -261,35 +261,27 @@ func (obj *NspawnRes) CheckApply(apply bool) (bool, error) {
|
|||||||
|
|
||||||
// Cmp compares two resources and returns an error if they are not equivalent.
|
// Cmp compares two resources and returns an error if they are not equivalent.
|
||||||
func (obj *NspawnRes) Cmp(r engine.Res) error {
|
func (obj *NspawnRes) 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 *NspawnRes) Compare(r engine.Res) bool {
|
|
||||||
// we can only compare NspawnRes to others of the same resource kind
|
// we can only compare NspawnRes to others of the same resource kind
|
||||||
res, ok := r.(*NspawnRes)
|
res, ok := r.(*NspawnRes)
|
||||||
if !ok {
|
if !ok {
|
||||||
return false
|
return fmt.Errorf("not a %s", obj.Kind())
|
||||||
}
|
}
|
||||||
|
|
||||||
if obj.State != res.State {
|
if obj.State != res.State {
|
||||||
return false
|
return fmt.Errorf("the State differs")
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: why is res.svc ever nil?
|
// TODO: why is res.svc ever nil?
|
||||||
if (obj.svc == nil) != (res.svc == nil) { // xor
|
if (obj.svc == nil) != (res.svc == nil) { // xor
|
||||||
return false
|
return fmt.Errorf("the svc differs")
|
||||||
}
|
}
|
||||||
if obj.svc != nil && res.svc != nil {
|
if obj.svc != nil && res.svc != nil {
|
||||||
if !obj.svc.Compare(res.svc) {
|
if err := obj.svc.Cmp(res.svc); err != nil {
|
||||||
return false
|
return errwrap.Wrapf(err, "the svc differs")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return true
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// NspawnUID is a unique resource identifier.
|
// NspawnUID is a unique resource identifier.
|
||||||
|
|||||||
@@ -295,33 +295,25 @@ func (obj *PasswordRes) CheckApply(apply bool) (bool, error) {
|
|||||||
|
|
||||||
// Cmp compares two resources and returns an error if they are not equivalent.
|
// Cmp compares two resources and returns an error if they are not equivalent.
|
||||||
func (obj *PasswordRes) Cmp(r engine.Res) error {
|
func (obj *PasswordRes) 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 *PasswordRes) Compare(r engine.Res) bool {
|
|
||||||
// we can only compare PasswordRes to others of the same resource kind
|
// we can only compare PasswordRes to others of the same resource kind
|
||||||
res, ok := r.(*PasswordRes)
|
res, ok := r.(*PasswordRes)
|
||||||
if !ok {
|
if !ok {
|
||||||
return false
|
return fmt.Errorf("not a %s", obj.Kind())
|
||||||
}
|
}
|
||||||
|
|
||||||
if obj.Length != res.Length {
|
if obj.Length != res.Length {
|
||||||
return false
|
return fmt.Errorf("the Length differs")
|
||||||
}
|
}
|
||||||
// TODO: we *could* optimize by allowing CheckApply to move from
|
// TODO: we *could* optimize by allowing CheckApply to move from
|
||||||
// saved->!saved, by removing the file, but not likely worth it!
|
// saved->!saved, by removing the file, but not likely worth it!
|
||||||
if obj.Saved != res.Saved {
|
if obj.Saved != res.Saved {
|
||||||
return false
|
return fmt.Errorf("the Saved differs")
|
||||||
}
|
}
|
||||||
if obj.CheckRecovery != res.CheckRecovery {
|
if obj.CheckRecovery != res.CheckRecovery {
|
||||||
return false
|
return fmt.Errorf("the CheckRecovery differs")
|
||||||
}
|
}
|
||||||
|
|
||||||
return true
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// PasswordUID is the UID struct for PasswordRes.
|
// PasswordUID is the UID struct for PasswordRes.
|
||||||
|
|||||||
@@ -115,24 +115,16 @@ func (obj *PrintRes) CheckApply(apply bool) (bool, error) {
|
|||||||
|
|
||||||
// Cmp compares two resources and returns an error if they are not equivalent.
|
// Cmp compares two resources and returns an error if they are not equivalent.
|
||||||
func (obj *PrintRes) Cmp(r engine.Res) error {
|
func (obj *PrintRes) 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 *PrintRes) Compare(r engine.Res) bool {
|
|
||||||
// we can only compare PrintRes to others of the same resource kind
|
// we can only compare PrintRes to others of the same resource kind
|
||||||
res, ok := r.(*PrintRes)
|
res, ok := r.(*PrintRes)
|
||||||
if !ok {
|
if !ok {
|
||||||
return false
|
return fmt.Errorf("not a %s", obj.Kind())
|
||||||
}
|
}
|
||||||
|
|
||||||
if obj.Msg != res.Msg {
|
if obj.Msg != res.Msg {
|
||||||
return false
|
return fmt.Errorf("the Msg differs")
|
||||||
}
|
}
|
||||||
return true
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// PrintUID is the UID struct for PrintRes.
|
// PrintUID is the UID struct for PrintRes.
|
||||||
|
|||||||
@@ -354,31 +354,23 @@ func (obj *SvcRes) CheckApply(apply bool) (bool, error) {
|
|||||||
|
|
||||||
// Cmp compares two resources and returns an error if they are not equivalent.
|
// Cmp compares two resources and returns an error if they are not equivalent.
|
||||||
func (obj *SvcRes) Cmp(r engine.Res) error {
|
func (obj *SvcRes) 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 *SvcRes) Compare(r engine.Res) bool {
|
|
||||||
// we can only compare SvcRes to others of the same resource kind
|
// we can only compare SvcRes to others of the same resource kind
|
||||||
res, ok := r.(*SvcRes)
|
res, ok := r.(*SvcRes)
|
||||||
if !ok {
|
if !ok {
|
||||||
return false
|
return fmt.Errorf("not a %s", obj.Kind())
|
||||||
}
|
}
|
||||||
|
|
||||||
if obj.State != res.State {
|
if obj.State != res.State {
|
||||||
return false
|
return fmt.Errorf("the State differs")
|
||||||
}
|
}
|
||||||
if obj.Startup != res.Startup {
|
if obj.Startup != res.Startup {
|
||||||
return false
|
return fmt.Errorf("the Startup differs")
|
||||||
}
|
}
|
||||||
if obj.Session != res.Session {
|
if obj.Session != res.Session {
|
||||||
return false
|
return fmt.Errorf("the Session differs")
|
||||||
}
|
}
|
||||||
|
|
||||||
return true
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// SvcUID is the UID struct for SvcRes.
|
// SvcUID is the UID struct for SvcRes.
|
||||||
|
|||||||
@@ -199,25 +199,17 @@ func (obj *TestRes) CheckApply(apply bool) (bool, error) {
|
|||||||
|
|
||||||
// Cmp compares two resources and returns an error if they are not equivalent.
|
// Cmp compares two resources and returns an error if they are not equivalent.
|
||||||
func (obj *TestRes) Cmp(r engine.Res) error {
|
func (obj *TestRes) 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 *TestRes) Compare(r engine.Res) bool {
|
|
||||||
// we can only compare TestRes to others of the same resource kind
|
// we can only compare TestRes to others of the same resource kind
|
||||||
res, ok := r.(*TestRes)
|
res, ok := r.(*TestRes)
|
||||||
if !ok {
|
if !ok {
|
||||||
return false
|
return fmt.Errorf("not a %s", obj.Kind())
|
||||||
}
|
}
|
||||||
//if obj.Name != res.Name {
|
//if obj.Name != res.Name {
|
||||||
// return false
|
// return false
|
||||||
//}
|
//}
|
||||||
|
|
||||||
if obj.CompareFail || res.CompareFail {
|
if obj.CompareFail || res.CompareFail {
|
||||||
return false
|
return fmt.Errorf("the CompareFail is true")
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: yes, I know the long manual version is absurd, but I couldn't
|
// TODO: yes, I know the long manual version is absurd, but I couldn't
|
||||||
@@ -228,145 +220,145 @@ func (obj *TestRes) Compare(r engine.Res) bool {
|
|||||||
//}
|
//}
|
||||||
|
|
||||||
if obj.Bool != res.Bool {
|
if obj.Bool != res.Bool {
|
||||||
return false
|
return fmt.Errorf("the Bool differs")
|
||||||
}
|
}
|
||||||
if obj.Str != res.Str {
|
if obj.Str != res.Str {
|
||||||
return false
|
return fmt.Errorf("the Str differs")
|
||||||
}
|
}
|
||||||
|
|
||||||
if obj.Int != res.Int {
|
if obj.Int != res.Int {
|
||||||
return false
|
return fmt.Errorf("the Str differs")
|
||||||
}
|
}
|
||||||
if obj.Int8 != res.Int8 {
|
if obj.Int8 != res.Int8 {
|
||||||
return false
|
return fmt.Errorf("the Int8 differs")
|
||||||
}
|
}
|
||||||
if obj.Int16 != res.Int16 {
|
if obj.Int16 != res.Int16 {
|
||||||
return false
|
return fmt.Errorf("the Int16 differs")
|
||||||
}
|
}
|
||||||
if obj.Int32 != res.Int32 {
|
if obj.Int32 != res.Int32 {
|
||||||
return false
|
return fmt.Errorf("the Int32 differs")
|
||||||
}
|
}
|
||||||
if obj.Int64 != res.Int64 {
|
if obj.Int64 != res.Int64 {
|
||||||
return false
|
return fmt.Errorf("the Int64 differs")
|
||||||
}
|
}
|
||||||
|
|
||||||
if obj.Uint != res.Uint {
|
if obj.Uint != res.Uint {
|
||||||
return false
|
return fmt.Errorf("the Uint differs")
|
||||||
}
|
}
|
||||||
if obj.Uint8 != res.Uint8 {
|
if obj.Uint8 != res.Uint8 {
|
||||||
return false
|
return fmt.Errorf("the Uint8 differs")
|
||||||
}
|
}
|
||||||
if obj.Uint16 != res.Uint16 {
|
if obj.Uint16 != res.Uint16 {
|
||||||
return false
|
return fmt.Errorf("the Uint16 differs")
|
||||||
}
|
}
|
||||||
if obj.Uint32 != res.Uint32 {
|
if obj.Uint32 != res.Uint32 {
|
||||||
return false
|
return fmt.Errorf("the Uint32 differs")
|
||||||
}
|
}
|
||||||
if obj.Uint64 != res.Uint64 {
|
if obj.Uint64 != res.Uint64 {
|
||||||
return false
|
return fmt.Errorf("the Uint64 differs")
|
||||||
}
|
}
|
||||||
|
|
||||||
//if obj.Uintptr
|
//if obj.Uintptr
|
||||||
if obj.Byte != res.Byte {
|
if obj.Byte != res.Byte {
|
||||||
return false
|
return fmt.Errorf("the Byte differs")
|
||||||
}
|
}
|
||||||
if obj.Rune != res.Rune {
|
if obj.Rune != res.Rune {
|
||||||
return false
|
return fmt.Errorf("the Rune differs")
|
||||||
}
|
}
|
||||||
|
|
||||||
if obj.Float32 != res.Float32 {
|
if obj.Float32 != res.Float32 {
|
||||||
return false
|
return fmt.Errorf("the Float32 differs")
|
||||||
}
|
}
|
||||||
if obj.Float64 != res.Float64 {
|
if obj.Float64 != res.Float64 {
|
||||||
return false
|
return fmt.Errorf("the Float64 differs")
|
||||||
}
|
}
|
||||||
if obj.Complex64 != res.Complex64 {
|
if obj.Complex64 != res.Complex64 {
|
||||||
return false
|
return fmt.Errorf("the Complex64 differs")
|
||||||
}
|
}
|
||||||
if obj.Complex128 != res.Complex128 {
|
if obj.Complex128 != res.Complex128 {
|
||||||
return false
|
return fmt.Errorf("the Complex128 differs")
|
||||||
}
|
}
|
||||||
|
|
||||||
if (obj.BoolPtr == nil) != (res.BoolPtr == nil) { // xor
|
if (obj.BoolPtr == nil) != (res.BoolPtr == nil) { // xor
|
||||||
return false
|
return fmt.Errorf("the BoolPtr differs")
|
||||||
}
|
}
|
||||||
if obj.BoolPtr != nil && res.BoolPtr != nil {
|
if obj.BoolPtr != nil && res.BoolPtr != nil {
|
||||||
if *obj.BoolPtr != *res.BoolPtr { // compare
|
if *obj.BoolPtr != *res.BoolPtr { // compare
|
||||||
return false
|
return fmt.Errorf("the BoolPtr differs")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (obj.StringPtr == nil) != (res.StringPtr == nil) { // xor
|
if (obj.StringPtr == nil) != (res.StringPtr == nil) { // xor
|
||||||
return false
|
return fmt.Errorf("the StringPtr differs")
|
||||||
}
|
}
|
||||||
if obj.StringPtr != nil && res.StringPtr != nil {
|
if obj.StringPtr != nil && res.StringPtr != nil {
|
||||||
if *obj.StringPtr != *res.StringPtr { // compare
|
if *obj.StringPtr != *res.StringPtr { // compare
|
||||||
return false
|
return fmt.Errorf("the StringPtr differs")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (obj.Int64Ptr == nil) != (res.Int64Ptr == nil) { // xor
|
if (obj.Int64Ptr == nil) != (res.Int64Ptr == nil) { // xor
|
||||||
return false
|
return fmt.Errorf("the Int64Ptr differs")
|
||||||
}
|
}
|
||||||
if obj.Int64Ptr != nil && res.Int64Ptr != nil {
|
if obj.Int64Ptr != nil && res.Int64Ptr != nil {
|
||||||
if *obj.Int64Ptr != *res.Int64Ptr { // compare
|
if *obj.Int64Ptr != *res.Int64Ptr { // compare
|
||||||
return false
|
return fmt.Errorf("the Int64Ptr differs")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (obj.Int8Ptr == nil) != (res.Int8Ptr == nil) { // xor
|
if (obj.Int8Ptr == nil) != (res.Int8Ptr == nil) { // xor
|
||||||
return false
|
return fmt.Errorf("the Int8Ptr differs")
|
||||||
}
|
}
|
||||||
if obj.Int8Ptr != nil && res.Int8Ptr != nil {
|
if obj.Int8Ptr != nil && res.Int8Ptr != nil {
|
||||||
if *obj.Int8Ptr != *res.Int8Ptr { // compare
|
if *obj.Int8Ptr != *res.Int8Ptr { // compare
|
||||||
return false
|
return fmt.Errorf("the Int8Ptr differs")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (obj.Uint8Ptr == nil) != (res.Uint8Ptr == nil) { // xor
|
if (obj.Uint8Ptr == nil) != (res.Uint8Ptr == nil) { // xor
|
||||||
return false
|
return fmt.Errorf("the Uint8Ptr differs")
|
||||||
}
|
}
|
||||||
if obj.Uint8Ptr != nil && res.Uint8Ptr != nil {
|
if obj.Uint8Ptr != nil && res.Uint8Ptr != nil {
|
||||||
if *obj.Uint8Ptr != *res.Uint8Ptr { // compare
|
if *obj.Uint8Ptr != *res.Uint8Ptr { // compare
|
||||||
return false
|
return fmt.Errorf("the Uint8Ptr differs")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if !reflect.DeepEqual(obj.Int8PtrPtrPtr, res.Int8PtrPtrPtr) {
|
if !reflect.DeepEqual(obj.Int8PtrPtrPtr, res.Int8PtrPtrPtr) {
|
||||||
return false
|
return fmt.Errorf("the Int8PtrPtrPtr differs")
|
||||||
}
|
}
|
||||||
|
|
||||||
if !reflect.DeepEqual(obj.SliceString, res.SliceString) {
|
if !reflect.DeepEqual(obj.SliceString, res.SliceString) {
|
||||||
return false
|
return fmt.Errorf("the SliceString differs")
|
||||||
}
|
}
|
||||||
if !reflect.DeepEqual(obj.MapIntFloat, res.MapIntFloat) {
|
if !reflect.DeepEqual(obj.MapIntFloat, res.MapIntFloat) {
|
||||||
return false
|
return fmt.Errorf("the MapIntFloat differs")
|
||||||
}
|
}
|
||||||
if !reflect.DeepEqual(obj.MixedStruct, res.MixedStruct) {
|
if !reflect.DeepEqual(obj.MixedStruct, res.MixedStruct) {
|
||||||
return false
|
return fmt.Errorf("the MixedStruct differs")
|
||||||
}
|
}
|
||||||
if !reflect.DeepEqual(obj.Interface, res.Interface) {
|
if !reflect.DeepEqual(obj.Interface, res.Interface) {
|
||||||
return false
|
return fmt.Errorf("the Interface differs")
|
||||||
}
|
}
|
||||||
|
|
||||||
if obj.AnotherStr != res.AnotherStr {
|
if obj.AnotherStr != res.AnotherStr {
|
||||||
return false
|
return fmt.Errorf("the AnotherStr differs")
|
||||||
}
|
}
|
||||||
|
|
||||||
if obj.ValidateBool != res.ValidateBool {
|
if obj.ValidateBool != res.ValidateBool {
|
||||||
return false
|
return fmt.Errorf("the ValidateBool differs")
|
||||||
}
|
}
|
||||||
if obj.ValidateError != res.ValidateError {
|
if obj.ValidateError != res.ValidateError {
|
||||||
return false
|
return fmt.Errorf("the ValidateError differs")
|
||||||
}
|
}
|
||||||
if obj.AlwaysGroup != res.AlwaysGroup {
|
if obj.AlwaysGroup != res.AlwaysGroup {
|
||||||
return false
|
return fmt.Errorf("the AlwaysGroup differs")
|
||||||
}
|
}
|
||||||
if obj.SendValue != res.SendValue {
|
if obj.SendValue != res.SendValue {
|
||||||
return false
|
return fmt.Errorf("the SendValue differs")
|
||||||
}
|
}
|
||||||
|
|
||||||
if obj.Comment != res.Comment {
|
if obj.Comment != res.Comment {
|
||||||
return false
|
return fmt.Errorf("the Comment differs")
|
||||||
}
|
}
|
||||||
|
|
||||||
return true
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// TestUID is the UID struct for TestRes.
|
// TestUID is the UID struct for TestRes.
|
||||||
|
|||||||
@@ -113,25 +113,17 @@ func (obj *TimerRes) CheckApply(apply bool) (bool, error) {
|
|||||||
|
|
||||||
// Cmp compares two resources and returns an error if they are not equivalent.
|
// Cmp compares two resources and returns an error if they are not equivalent.
|
||||||
func (obj *TimerRes) Cmp(r engine.Res) error {
|
func (obj *TimerRes) 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 *TimerRes) Compare(r engine.Res) bool {
|
|
||||||
// we can only compare TimerRes to others of the same resource kind
|
// we can only compare TimerRes to others of the same resource kind
|
||||||
res, ok := r.(*TimerRes)
|
res, ok := r.(*TimerRes)
|
||||||
if !ok {
|
if !ok {
|
||||||
return false
|
return fmt.Errorf("not a %s", obj.Kind())
|
||||||
}
|
}
|
||||||
|
|
||||||
if obj.Interval != res.Interval {
|
if obj.Interval != res.Interval {
|
||||||
return false
|
return fmt.Errorf("the Interval differs")
|
||||||
}
|
}
|
||||||
|
|
||||||
return true
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// TimerUID is the UID struct for TimerRes.
|
// TimerUID is the UID struct for TimerRes.
|
||||||
|
|||||||
@@ -273,45 +273,37 @@ func (obj *UserRes) CheckApply(apply bool) (bool, error) {
|
|||||||
|
|
||||||
// Cmp compares two resources and returns an error if they are not equivalent.
|
// Cmp compares two resources and returns an error if they are not equivalent.
|
||||||
func (obj *UserRes) Cmp(r engine.Res) error {
|
func (obj *UserRes) 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 *UserRes) Compare(r engine.Res) bool {
|
|
||||||
// we can only compare UserRes to others of the same resource kind
|
// we can only compare UserRes to others of the same resource kind
|
||||||
res, ok := r.(*UserRes)
|
res, ok := r.(*UserRes)
|
||||||
if !ok {
|
if !ok {
|
||||||
return false
|
return fmt.Errorf("not a %s", obj.Kind())
|
||||||
}
|
}
|
||||||
|
|
||||||
if obj.State != res.State {
|
if obj.State != res.State {
|
||||||
return false
|
return fmt.Errorf("the State differs")
|
||||||
}
|
}
|
||||||
if (obj.UID == nil) != (res.UID == nil) {
|
if (obj.UID == nil) != (res.UID == nil) {
|
||||||
return false
|
return fmt.Errorf("the UID differs")
|
||||||
}
|
}
|
||||||
if obj.UID != nil && res.UID != nil {
|
if obj.UID != nil && res.UID != nil {
|
||||||
if *obj.UID != *res.UID {
|
if *obj.UID != *res.UID {
|
||||||
return false
|
return fmt.Errorf("the UID differs")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (obj.GID == nil) != (res.GID == nil) {
|
if (obj.GID == nil) != (res.GID == nil) {
|
||||||
return false
|
return fmt.Errorf("the GID differs")
|
||||||
}
|
}
|
||||||
if obj.GID != nil && res.GID != nil {
|
if obj.GID != nil && res.GID != nil {
|
||||||
if *obj.GID != *res.GID {
|
if *obj.GID != *res.GID {
|
||||||
return false
|
return fmt.Errorf("the GID differs")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (obj.Groups == nil) != (res.Groups == nil) {
|
if (obj.Groups == nil) != (res.Groups == nil) {
|
||||||
return false
|
return fmt.Errorf("the Group differs")
|
||||||
}
|
}
|
||||||
if obj.Groups != nil && res.Groups != nil {
|
if obj.Groups != nil && res.Groups != nil {
|
||||||
if len(obj.Groups) != len(res.Groups) {
|
if len(obj.Groups) != len(res.Groups) {
|
||||||
return false
|
return fmt.Errorf("the Group differs")
|
||||||
}
|
}
|
||||||
objGroups := obj.Groups
|
objGroups := obj.Groups
|
||||||
resGroups := res.Groups
|
resGroups := res.Groups
|
||||||
@@ -319,22 +311,22 @@ func (obj *UserRes) Compare(r engine.Res) bool {
|
|||||||
sort.Strings(resGroups)
|
sort.Strings(resGroups)
|
||||||
for i := range objGroups {
|
for i := range objGroups {
|
||||||
if objGroups[i] != resGroups[i] {
|
if objGroups[i] != resGroups[i] {
|
||||||
return false
|
return fmt.Errorf("the Group differs at index: %d", i)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (obj.HomeDir == nil) != (res.HomeDir == nil) {
|
if (obj.HomeDir == nil) != (res.HomeDir == nil) {
|
||||||
return false
|
return fmt.Errorf("the HomeDirs differs")
|
||||||
}
|
}
|
||||||
if obj.HomeDir != nil && res.HomeDir != nil {
|
if obj.HomeDir != nil && res.HomeDir != nil {
|
||||||
if *obj.HomeDir != *obj.HomeDir {
|
if *obj.HomeDir != *res.HomeDir {
|
||||||
return false
|
return fmt.Errorf("the HomeDir differs")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if obj.AllowDuplicateUID != res.AllowDuplicateUID {
|
if obj.AllowDuplicateUID != res.AllowDuplicateUID {
|
||||||
return false
|
return fmt.Errorf("the AllowDuplicateUID differs")
|
||||||
}
|
}
|
||||||
return true
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// UserUID is the UID struct for UserRes.
|
// UserUID is the UID struct for UserRes.
|
||||||
|
|||||||
Reference in New Issue
Block a user