Fix ItemMatches function and adding some basic tests

This commit is contained in:
Marius Orcsik 2021-03-27 14:06:24 +01:00
parent 95774ab532
commit 57a41d04da
No known key found for this signature in database
GPG key ID: 7970BDC7D4CB2674
2 changed files with 60 additions and 3 deletions

View file

@ -16,7 +16,7 @@ func ItemsEqual(it, with Item) bool {
if IsNil(it) || IsNil(with) {
return with == it
}
result := true
result := false
if it.IsCollection() {
if it.GetType() == CollectionOfItems {
OnItemCollection(it, func(c *ItemCollection) error {
@ -115,4 +115,4 @@ func IsNil(it Item) bool {
})
}
return isNil
}
}

View file

@ -188,4 +188,61 @@ func TestIsNil(t *testing.T) {
}
})
}
}
}
func TestItemsEqual1(t *testing.T) {
type args struct {
it Item
with Item
}
tests := []struct {
name string
args args
want bool
}{
{
name: "nil",
args: args{},
want: true,
},
{
name: "equal empty items",
args: args{
it: &Object{},
with: &Actor{},
},
want: true,
},
{
name: "equal same ID items",
args: args{
it: &Object{ID: "example-1"},
with: &Object{ID: "example-1"},
},
want: true,
},
{
name: "different IDs",
args: args{
it: &Object{ID: "example-1"},
with: &Object{ID: "example-2"},
},
want: false,
},
{
name: "different properties",
args: args{
it: &Object{ID: "example-1"},
with: &Object{Type: ArticleType},
},
want: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := ItemsEqual(tt.args.it, tt.args.with); got != tt.want {
t.Errorf("ItemsEqual() = %v, want %v", got, tt.want)
}
})
}
}