2018-07-16 13:48:37 +00:00
|
|
|
package activitypub
|
|
|
|
|
|
|
|
import (
|
2019-01-22 15:37:30 +00:00
|
|
|
as "github.com/go-ap/activitystreams"
|
2018-07-16 13:48:37 +00:00
|
|
|
"reflect"
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestInboxNew(t *testing.T) {
|
|
|
|
i := InboxNew()
|
|
|
|
|
2018-10-11 09:26:00 +00:00
|
|
|
id := as.ObjectID("inbox")
|
2018-07-16 13:48:37 +00:00
|
|
|
if i.ID != id {
|
|
|
|
t.Errorf("%T should be initialized with %q as %T", i, id, id)
|
|
|
|
}
|
|
|
|
if len(i.Name) != 0 {
|
|
|
|
t.Errorf("%T should be initialized with 0 length Name", i)
|
|
|
|
}
|
|
|
|
if len(i.Content) != 0 {
|
|
|
|
t.Errorf("%T should be initialized with 0 length Content", i)
|
|
|
|
}
|
|
|
|
if len(i.Summary) != 0 {
|
|
|
|
t.Errorf("%T should be initialized with 0 length Summary", i)
|
|
|
|
}
|
|
|
|
if i.TotalItems != 0 {
|
|
|
|
t.Errorf("%T should be initialized with 0 TotalItems", i)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestInboxStream_GetID(t *testing.T) {
|
|
|
|
o := InboxStream{}
|
2018-07-25 09:47:03 +00:00
|
|
|
if *o.GetID() != "" {
|
2018-07-16 13:48:37 +00:00
|
|
|
t.Errorf("%T should be initialized with empty %T", o, o.GetID())
|
|
|
|
}
|
2018-10-11 09:26:00 +00:00
|
|
|
id := as.ObjectID("test_out_stream")
|
2018-07-16 13:48:37 +00:00
|
|
|
o.ID = id
|
2018-07-25 09:47:03 +00:00
|
|
|
if *o.GetID() != id {
|
2018-07-16 13:48:37 +00:00
|
|
|
t.Errorf("%T should have %T as %q", o, id, id)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestInboxStream_GetType(t *testing.T) {
|
|
|
|
o := InboxStream{}
|
|
|
|
|
|
|
|
if o.GetType() != "" {
|
|
|
|
t.Errorf("%T should be initialized with empty %T", o, o.GetType())
|
|
|
|
}
|
|
|
|
|
2018-10-11 09:26:00 +00:00
|
|
|
o.Type = as.OrderedCollectionType
|
|
|
|
if o.GetType() != as.OrderedCollectionType {
|
|
|
|
t.Errorf("%T should have %T as %q", o, o.GetType(), as.OrderedCollectionType)
|
2018-07-16 13:48:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestInboxStream_Append(t *testing.T) {
|
|
|
|
o := InboxStream{}
|
|
|
|
|
2018-10-11 09:26:00 +00:00
|
|
|
val := as.Object{ID: as.ObjectID("grrr")}
|
2018-07-16 13:48:37 +00:00
|
|
|
|
|
|
|
o.Append(val)
|
|
|
|
if o.TotalItems != 1 {
|
|
|
|
t.Errorf("%T should have exactly an element, found %d", o, o.TotalItems)
|
|
|
|
}
|
|
|
|
if !reflect.DeepEqual(o.OrderedItems[0], val) {
|
|
|
|
t.Errorf("First item in %T.%T does not match %q", o, o.OrderedItems, val.ID)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
func TestInbox_Append(t *testing.T) {
|
|
|
|
i := InboxNew()
|
|
|
|
|
2018-10-11 09:26:00 +00:00
|
|
|
val := as.Object{ID: as.ObjectID("grrr")}
|
2018-07-16 13:48:37 +00:00
|
|
|
|
|
|
|
i.Append(val)
|
|
|
|
if i.TotalItems != 1 {
|
|
|
|
t.Errorf("%T should have exactly an element, found %d", i, i.TotalItems)
|
|
|
|
}
|
|
|
|
if !reflect.DeepEqual(i.OrderedItems[0], val) {
|
|
|
|
t.Errorf("First item in %T.%T does not match %q", i, i.OrderedItems, val.ID)
|
|
|
|
}
|
|
|
|
}
|