From 9e61b5fcea67bfcbb12c5211ed8377c4f01c5134 Mon Sep 17 00:00:00 2001 From: Marius Orcsik Date: Tue, 10 Apr 2018 20:09:06 +0200 Subject: [PATCH] Test deduplication with two object arrays --- src/activitypub/object.go | 7 ++----- src/activitypub/object_test.go | 13 ++++++++++++- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/activitypub/object.go b/src/activitypub/object.go index 4ea0b57..a0a7756 100644 --- a/src/activitypub/object.go +++ b/src/activitypub/object.go @@ -284,6 +284,7 @@ func RecipientsDeduplication(recArgs ...*ObjectsArr) error { if recList == nil { continue } + toRemove := make([]int, 0) for i, rec := range *recList { save := true @@ -301,11 +302,7 @@ func RecipientsDeduplication(recArgs ...*ObjectsArr) error { sort.Sort(sort.Reverse(sort.IntSlice(toRemove))) for _, idx := range toRemove { - if idx == len(*recList) { - *recList = (*recList)[:idx] - } else { - *recList = append((*recList)[:idx], (*recList)[idx+1:]...) - } + *recList = append((*recList)[:idx], (*recList)[idx+1:]...) } } return nil diff --git a/src/activitypub/object_test.go b/src/activitypub/object_test.go index 3c7f459..a12186c 100644 --- a/src/activitypub/object_test.go +++ b/src/activitypub/object_test.go @@ -178,7 +178,18 @@ func TestRecipientsDeduplication(t *testing.T) { RecipientsDeduplication(&first) if len(first) != 4 { - t.Errorf("Objects array should have exactly 8(eight) elements, not %d", len(first)) + t.Errorf("Objects array should have exactly 4(four) elements, not %d", len(first)) } + second := make(ObjectsArr, 0) + second.Append(bar) + second.Append(foo) + + RecipientsDeduplication(&first, &second) + if len(first) != 4 { + t.Errorf("First Objects array should have exactly 8(eight) elements, not %d", len(first)) + } + if len(second) != 0 { + t.Errorf("Second Objects array should have exactly 0(zero) elements, not %d", len(second)) + } }