resources: Simplify the resource Compare functions

This removes one level of indentation and simplifies the code.
This commit is contained in:
James Shubin
2017-05-31 16:42:29 -04:00
parent bd4563b699
commit 6e503cc79b
15 changed files with 373 additions and 332 deletions

View File

@@ -22,9 +22,49 @@ import (
"encoding/base64"
"encoding/gob"
"testing"
//"github.com/purpleidea/mgmt/event"
)
func TestCompare1(t *testing.T) {
r1 := &NoopRes{}
r2 := &NoopRes{}
r3 := &FileRes{}
if !r1.Compare(r2) || !r2.Compare(r1) {
t.Error("The two resources do not match!")
}
if r1.Compare(r3) || r3.Compare(r1) {
t.Error("The two resources should not match!")
}
}
func TestCompare2(t *testing.T) {
r1 := &NoopRes{
BaseRes: BaseRes{
Name: "noop1",
MetaParams: MetaParams{
Noop: true,
},
},
}
r2 := &NoopRes{
BaseRes: BaseRes{
Name: "noop1", // same nampe
MetaParams: MetaParams{
Noop: false, // different noop
},
},
}
if !r2.Compare(r1) { // going from noop(false) -> noop(true) is okay!
t.Error("The two resources do not match!")
}
if r1.Compare(r2) { // going from noop(true) -> noop(false) is not okay!
t.Error("The two resources should not match!")
}
}
func TestMiscEncodeDecode1(t *testing.T) {
var err error
//gob.Register( &NoopRes{} ) // happens in noop.go : init()