Changes
4 changed files (+73/-2)
-
-
@@ -5,6 +5,10 @@ var validCollectionTypes = [...]ActivityVocabularyType{CollectionType, OrderedCo// Page represents a Web Page. type Page ObjectOrLink type CollectionInterface interface { Append(o ObjectOrLink) error } // Collection is a subtype of Object that represents ordered or unordered sets of Object or Link instances. type Collection struct { apObject
-
@@ -96,3 +100,17 @@ func CollectionPageNew(parent *Collection) *CollectionPage {func OrderedCollectionPageNew(parent *OrderedCollection) *OrderedCollectionPage { return &OrderedCollectionPage{PartOf: parent} } // Append adds an element to an OrderedCollection func (c *OrderedCollection) Append(o ObjectOrLink) error { c.OrderedItems = append(c.OrderedItems, o) c.TotalItems++ return nil } // Append adds an element to an Collection func (c *Collection) Append(o ObjectOrLink) error { c.Items = append(c.Items, o) c.TotalItems++ return nil }
-
-
-
@@ -1,6 +1,9 @@package activitypub import "testing" import ( "reflect" "testing" ) func TestCollectionNew(t *testing.T) { var testValue = ObjectID("test")
-
@@ -55,3 +58,35 @@ func TestValidCollectionType(t *testing.T) {} } } func Test_OrderedCollection_Append(t *testing.T) { id := ObjectID("test") val := apObject{ID: ObjectID("grrr")} c := OrderedCollectionNew(id) c.Append(val) if c.TotalItems != 1 { t.Errorf("Inbox collection of %q should have exactly an Object", c.Object().ID) } if !reflect.DeepEqual(c.OrderedItems[0].Object(), val) { t.Errorf("First item in Inbox is does not match %q", val.ID) } } func Test_Collection_Append(t *testing.T) { id := ObjectID("test") val := apObject{ID: ObjectID("grrr")} c := CollectionNew(id) c.Append(val) if c.TotalItems != 1 { t.Errorf("Inbox collection of %q should have exactly an Object", c.Object().ID) } if !reflect.DeepEqual(c.Items[0].Object(), val) { t.Errorf("First item in Inbox is does not match %q", val.ID) } }
-
-
-
@@ -11,3 +11,21 @@ type (// Inbox is a type alias for an Ordered Collection Inbox OrderedCollection ) // InboxNew initializes a new Inbox func InboxNew() *Inbox { id := ObjectID("inbox") o := ObjectNew(id, OrderedCollectionType) i := Inbox{apObject: o} i.TotalItems = 0 return &i } // Append adds an element to an InboxStream func (i *InboxStream) Append(o ObjectOrLink) error { i.OrderedItems = append(i.OrderedItems, o) i.TotalItems++ return nil }
-
-
-
@@ -4,4 +4,4 @@ package activitypubtype ItemCollection []Item // Item struct type Item struct{} type Item ObjectOrLink
-