diff --git a/activity.go b/activity.go index 512ff5d..207d6d4 100644 --- a/activity.go +++ b/activity.go @@ -785,7 +785,7 @@ func (a Activity) GobEncode() ([]byte, error) { func (a *Activity) GobDecode([]byte) error { return errors.New(fmt.Sprintf("GobDecode is not implemented for %T", *a)) } - */ +*/ // Equals verifies if our receiver Object is equals with the "with" Object func (a Activity) Equals(with Item) bool { diff --git a/actor.go b/actor.go index 345b75d..287cbe3 100644 --- a/actor.go +++ b/actor.go @@ -245,7 +245,7 @@ func (a Actor) GobEncode() ([]byte, error) { func (a *Actor) GobDecode([]byte) error { return errors.New(fmt.Sprintf("GobDecode is not implemented for %T", *a)) } - */ +*/ type ( // Application describes a software application. diff --git a/actor_test.go b/actor_test.go index d1a5f0e..c70de32 100644 --- a/actor_test.go +++ b/actor_test.go @@ -376,8 +376,8 @@ func TestPublicKey_MarshalJSON(t *testing.T) { } func assertPersonWithTesting(fn canErrorFunc, expected Item) WithActorFn { - return func (p *Person) error { - if !assertDeepEquals(fn, p , expected) { + return func(p *Person) error { + if !assertDeepEquals(fn, p, expected) { return fmt.Errorf("not equal") } return nil diff --git a/collection.go b/collection.go index e6d6d5f..caedad2 100644 --- a/collection.go +++ b/collection.go @@ -288,7 +288,7 @@ func (c Collection) GobEncode() ([]byte, error) { func (c *Collection) GobDecode([]byte) error { return errors.New(fmt.Sprintf("GobDecode is not implemented for %T", *c)) } - */ +*/ // ToCollection func ToCollection(it Item) (*Collection, error) { diff --git a/collection_page.go b/collection_page.go index cca0918..5b1c859 100644 --- a/collection_page.go +++ b/collection_page.go @@ -252,7 +252,7 @@ func (c CollectionPage) GobEncode() ([]byte, error) { func (c *CollectionPage) GobDecode([]byte) error { return errors.New(fmt.Sprintf("GobDecode is not implemented for %T", *c)) } - */ +*/ // CollectionNew initializes a new CollectionPage func CollectionPageNew(parent CollectionInterface) *CollectionPage { diff --git a/collection_page_test.go b/collection_page_test.go index 956df87..721c6cd 100644 --- a/collection_page_test.go +++ b/collection_page_test.go @@ -145,23 +145,23 @@ func TestToCollectionPage(t *testing.T) { wantErr error }{ "CollectionPage": { - it: new(CollectionPage), - want: new(CollectionPage), + it: new(CollectionPage), + want: new(CollectionPage), wantErr: nil, }, "OrderedCollectionPage": { - it: new(OrderedCollectionPage), - want: new(CollectionPage), + it: new(OrderedCollectionPage), + want: new(CollectionPage), wantErr: err, }, "OrderedCollection": { - it: new(OrderedCollection), - want: new(CollectionPage), + it: new(OrderedCollection), + want: new(CollectionPage), wantErr: err, }, "Collection": { - it: new(Collection), - want: new(CollectionPage), + it: new(Collection), + want: new(CollectionPage), wantErr: err, }, } diff --git a/collection_test.go b/collection_test.go index b6eea1b..b6fe3ec 100644 --- a/collection_test.go +++ b/collection_test.go @@ -195,23 +195,23 @@ func TestToCollection(t *testing.T) { wantErr error }{ "Collection": { - it: new(Collection), - want: new(Collection), + it: new(Collection), + want: new(Collection), wantErr: nil, }, "CollectionPage": { - it: new(CollectionPage), - want: new(Collection), + it: new(CollectionPage), + want: new(Collection), wantErr: nil, }, "OrderedCollectionPage": { - it: new(OrderedCollectionPage), - want: new(Collection), + it: new(OrderedCollectionPage), + want: new(Collection), wantErr: err, }, "OrderedCollection": { - it: new(OrderedCollection), - want: new(Collection), + it: new(OrderedCollection), + want: new(Collection), wantErr: err, }, } diff --git a/decoding_json_test.go b/decoding_json_test.go index 6585910..f0c3698 100644 --- a/decoding_json_test.go +++ b/decoding_json_test.go @@ -136,9 +136,12 @@ func deepValueEqual(t canErrorFunc, v1, v2 reflect.Value, visited map[visit]bool case reflect.Struct: for i, n := 0, v1.NumField(); i < n; i++ { var ( - f1 = v1.Field(i); f2 = v2.Field(i) - n1 = v1.Type().Field(i).Name; n2 = v2.Type().Field(i).Name - t1 = f1.Type().Name(); t2 = f2.Type().Name() + f1 = v1.Field(i) + f2 = v2.Field(i) + n1 = v1.Type().Field(i).Name + n2 = v2.Type().Field(i).Name + t1 = f1.Type().Name() + t2 = f2.Type().Name() ) if !deepValueEqual(t, v1.Field(i), v2.Field(i), visited, depth+1) { t("Struct fields at pos %d %s[%s] and %s[%s] are not deeply equal", i, n1, t1, n2, t2) @@ -318,7 +321,7 @@ func TestUnmarshalJSON(t *testing.T) { name string data []byte want Item - err error + err error }{ { name: "empty", @@ -335,11 +338,11 @@ func TestUnmarshalJSON(t *testing.T) { { name: "IRIs", data: []byte(fmt.Sprintf("[%q, %q]", "http://example.com", "http://example.net")), - want: ItemCollection{ + want: ItemCollection{ IRI("http://example.com"), IRI("http://example.net"), }, - err: nil, + err: nil, }, { name: "object", @@ -357,10 +360,10 @@ func TestUnmarshalJSON(t *testing.T) { name: "collection-2-items", data: []byte(`{ "@context": "https://www.w3.org/ns/activitystreams", "id": "https://federated.git/inbox", "type": "OrderedCollection", "updated": "2021-08-08T16:09:05Z", "first": "https://federated.git/inbox?maxItems=100", "totalItems": 2, "orderedItems": [ { "id": "https://federated.git/activities/07440c39-64b2-4492-89cf-f5c2872cf4ff", "type": "Create", "attributedTo": "https://federated.git/actors/b1757243-080a-49dc-b832-42905d554b91", "to": [ "https://www.w3.org/ns/activitystreams#Public" ], "cc": [ "https://federated.git/actors/b1757243-080a-49dc-b832-42905d554b91/followers" ], "published": "2021-08-08T16:09:05Z", "actor": "https://federated.git/actors/b1757243-080a-49dc-b832-42905d554b91", "object": "https://federated.git/objects/3eb69f77-3b08-4bf1-8760-c7333e2900c4" }, { "id": "https://federated.git/activities/ab9a5511-cdb5-4585-8a48-775d1bf20121", "type": "Like", "attributedTo": "https://federated.git/actors/b1757243-080a-49dc-b832-42905d554b91", "to": [ "https://www.w3.org/ns/activitystreams#Public", "https://federated.git/actors/b1757243-080a-49dc-b832-42905d554b91" ], "published": "2021-08-08T16:09:05Z", "actor": "https://federated.git/actors/b1757243-080a-49dc-b832-42905d554b91", "object": "https://federated.git/objects/3eb69f77-3b08-4bf1-8760-c7333e2900c4" }]}`), want: &OrderedCollection{ - ID: "https://federated.git/inbox", - Type: OrderedCollectionType, + ID: "https://federated.git/inbox", + Type: OrderedCollectionType, Updated: time.Date(2021, 8, 8, 16, 9, 5, 0, time.UTC), - First: IRI("https://federated.git/inbox?maxItems=100"), + First: IRI("https://federated.git/inbox?maxItems=100"), OrderedItems: ItemCollection{ &Activity{ ID: "https://federated.git/activities/07440c39-64b2-4492-89cf-f5c2872cf4ff", @@ -384,7 +387,7 @@ func TestUnmarshalJSON(t *testing.T) { }, TotalItems: 2, }, - err: nil, + err: nil, }, } for _, tt := range tests { diff --git a/encoding_gob.go b/encoding_gob.go index 108f55f..fa0c7d7 100644 --- a/encoding_gob.go +++ b/encoding_gob.go @@ -14,11 +14,11 @@ type typeId int32 type gobEncoder struct { sent map[reflect.Type]typeId // which types we've already sent - w *bytes.Buffer - enc *gob.Encoder + w *bytes.Buffer + enc *gob.Encoder } -func (e *gobEncoder) encode (it Item) ([]byte, error) { +func (e *gobEncoder) encode(it Item) ([]byte, error) { err := e.enc.Encode(it) if err != nil { return nil, err @@ -26,7 +26,6 @@ func (e *gobEncoder) encode (it Item) ([]byte, error) { return e.w.Bytes(), nil } - //// GobEncode //func GobEncode(it Item) ([]byte, error) { // w := bytes.NewBuffer(make([]byte, 0)) @@ -45,24 +44,24 @@ func (e *gobEncoder) writeIRIProp(i IRI) error { return e.enc.Encode(i.String()) } -func (e *gobEncoder) writeGobProp (p string, b []byte) bool { +func (e *gobEncoder) writeGobProp(p string, b []byte) bool { c, _ := e.w.Write([]byte(p)) d, _ := e.w.Write(b) return c+d > 0 } -func (e *gobEncoder)writeItemGobProp (p string, it Item) bool { +func (e *gobEncoder) writeItemGobProp(p string, it Item) bool { return true } -func (e *gobEncoder)writeNaturalLanguageGobProp (p string, v NaturalLanguageValues) bool { +func (e *gobEncoder) writeNaturalLanguageGobProp(p string, v NaturalLanguageValues) bool { return true } -func (e *gobEncoder)writeIRIGobProp (p string, i LinkOrIRI) bool { +func (e *gobEncoder) writeIRIGobProp(p string, i LinkOrIRI) bool { return true } -func (e *gobEncoder)writeTimeGobProp (p string, t time.Time) bool { +func (e *gobEncoder) writeTimeGobProp(p string, t time.Time) bool { return true } -func (e *gobEncoder)writeDurationGobProp (p string, d time.Duration) bool { +func (e *gobEncoder) writeDurationGobProp(p string, d time.Duration) bool { return true } @@ -170,4 +169,4 @@ func (e *gobEncoder) writeObjectGobValue(o Object) (bool, error) { } return notEmpty, nil } - */ +*/ diff --git a/encoding_gob_test.go b/encoding_gob_test.go index d2208ad..02f4e0a 100644 --- a/encoding_gob_test.go +++ b/encoding_gob_test.go @@ -15,8 +15,8 @@ func TestMarshalGob(t *testing.T) { wantErr error }{ { - name: "empty object", - it: &Object{ + name: "empty object", + it: &Object{ ID: "test", }, want: []byte{}, @@ -25,10 +25,10 @@ func TestMarshalGob(t *testing.T) { } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - buf := bytes.NewBuffer(make([]byte,0)) + buf := bytes.NewBuffer(make([]byte, 0)) err := gob.NewEncoder(buf).Encode(tt.it) - if !errors.Is(err, tt.wantErr){ + if !errors.Is(err, tt.wantErr) { t.Errorf("MarshalGob() error = %s, wantErr %v", err, tt.wantErr) return } diff --git a/helpers_test.go b/helpers_test.go index 2aae9de..e2ee5b6 100644 --- a/helpers_test.go +++ b/helpers_test.go @@ -6,8 +6,8 @@ import ( ) func assertObjectWithTesting(fn canErrorFunc, expected Item) WithObjectFn { - return func (p *Object) error { - if !assertDeepEquals(fn, p , expected) { + return func(p *Object) error { + if !assertDeepEquals(fn, p, expected) { return fmt.Errorf("not equal") } return nil @@ -69,8 +69,8 @@ func TestOnObject(t *testing.T) { } func assertActivityWithTesting(fn canErrorFunc, expected Item) WithActivityFn { - return func (p *Activity) error { - if !assertDeepEquals(fn, p , expected) { + return func(p *Activity) error { + if !assertDeepEquals(fn, p, expected) { return fmt.Errorf("not equal") } return nil @@ -132,8 +132,8 @@ func TestOnActivity(t *testing.T) { } func assertIntransitiveActivityWithTesting(fn canErrorFunc, expected Item) WithIntransitiveActivityFn { - return func (p *IntransitiveActivity) error { - if !assertDeepEquals(fn, p , expected) { + return func(p *IntransitiveActivity) error { + if !assertDeepEquals(fn, p, expected) { return fmt.Errorf("not equal") } return nil @@ -195,8 +195,8 @@ func TestOnIntransitiveActivity(t *testing.T) { } func assertQuestionWithTesting(fn canErrorFunc, expected Item) WithQuestionFn { - return func (p *Question) error { - if !assertDeepEquals(fn, p , expected) { + return func(p *Question) error { + if !assertDeepEquals(fn, p, expected) { return fmt.Errorf("not equal") } return nil diff --git a/intransitive_activity.go b/intransitive_activity.go index 396c71d..0dcf9db 100644 --- a/intransitive_activity.go +++ b/intransitive_activity.go @@ -217,7 +217,7 @@ func (i IntransitiveActivity) GobEncode() ([]byte, error) { func (i *IntransitiveActivity) GobDecode([]byte) error { return errors.New(fmt.Sprintf("GobDecode is not implemented for %T", *i)) } - */ +*/ // IntransitiveActivityNew initializes a intransitive activity func IntransitiveActivityNew(id ID, typ ActivityVocabularyType) *IntransitiveActivity { diff --git a/iri.go b/iri.go index 3831ac2..6e54fd5 100644 --- a/iri.go +++ b/iri.go @@ -90,7 +90,7 @@ func (i IRI) GobEncode() ([]byte, error) { func (i *IRI) GobDecode([]byte) error { return errors.New(fmt.Sprintf("GobDecode is not implemented for %T", *i)) } - */ +*/ // AddPath concatenates el elements as a path to i func (i IRI) AddPath(el ...string) IRI { diff --git a/item.go b/item.go index 95aa39c..39f8236 100644 --- a/item.go +++ b/item.go @@ -51,7 +51,7 @@ func ItemsEqual(it, with Item) bool { } if it.IsObject() { if ActivityTypes.Contains(with.GetType()) { - OnActivity(it, func(i*Activity) error { + OnActivity(it, func(i *Activity) error { result = i.Equals(with) return nil }) diff --git a/link.go b/link.go index 6e2e341..20211b1 100644 --- a/link.go +++ b/link.go @@ -132,4 +132,4 @@ func (l Link) GobEncode() ([]byte, error) { func (l *Link) GobDecode([]byte) error { return errors.New(fmt.Sprintf("GobDecode is not implemented for %T", *l)) } - */ +*/ diff --git a/object_test.go b/object_test.go index 0343be3..3950713 100644 --- a/object_test.go +++ b/object_test.go @@ -473,7 +473,6 @@ func TestSource_UnmarshalJSON(t *testing.T) { func TestGetAPSource(t *testing.T) { data := []byte(`{"source": {"content": "test", "mediaType": "text/plain" }}`) - par := fastjson.Parser{} val, _ := par.ParseBytes(data) a := GetAPSource(val) diff --git a/ordered_collection_page_test.go b/ordered_collection_page_test.go index 95426a9..90430c7 100644 --- a/ordered_collection_page_test.go +++ b/ordered_collection_page_test.go @@ -124,23 +124,23 @@ func TestToOrderedCollectionPage(t *testing.T) { wantErr error }{ "OrderedCollectionPage": { - it: new(OrderedCollectionPage), - want: new(OrderedCollectionPage), + it: new(OrderedCollectionPage), + want: new(OrderedCollectionPage), wantErr: nil, }, "OrderedCollection": { - it: new(OrderedCollection), - want: new(OrderedCollectionPage), + it: new(OrderedCollection), + want: new(OrderedCollectionPage), wantErr: err, }, "Collection": { - it: new(Collection), - want: new(OrderedCollectionPage), + it: new(Collection), + want: new(OrderedCollectionPage), wantErr: err, }, "CollectionPage": { - it: new(CollectionPage), - want: new(OrderedCollectionPage), + it: new(CollectionPage), + want: new(OrderedCollectionPage), wantErr: err, }, } @@ -150,7 +150,7 @@ func TestToOrderedCollectionPage(t *testing.T) { if tt.wantErr != nil && err == nil { t.Errorf("ToOrderedCollectionPage() no error returned, wanted error = [%T]%s", tt.wantErr, tt.wantErr) return - } + } if err != nil { if tt.wantErr == nil { t.Errorf("ToOrderedCollectionPage() returned unexpected error[%T]%s", err, err) diff --git a/ordered_collection_test.go b/ordered_collection_test.go index f46f0e3..3af4e20 100644 --- a/ordered_collection_test.go +++ b/ordered_collection_test.go @@ -221,23 +221,23 @@ func TestToOrderedCollection(t *testing.T) { wantErr error }{ "OrderedCollection": { - it: new(OrderedCollection), - want: new(OrderedCollection), + it: new(OrderedCollection), + want: new(OrderedCollection), wantErr: nil, }, "OrderedCollectionPage": { - it: new(OrderedCollectionPage), - want: new(OrderedCollection), + it: new(OrderedCollectionPage), + want: new(OrderedCollection), wantErr: nil, }, "Collection": { - it: new(Collection), - want: new(OrderedCollection), + it: new(Collection), + want: new(OrderedCollection), wantErr: err, }, "CollectionPage": { - it: new(CollectionPage), - want: new(OrderedCollection), + it: new(CollectionPage), + want: new(OrderedCollection), wantErr: err, }, } diff --git a/place_test.go b/place_test.go index db8b527..33db7db 100644 --- a/place_test.go +++ b/place_test.go @@ -46,8 +46,8 @@ func TestPlace_Clean(t *testing.T) { } func assertPlaceWithTesting(fn canErrorFunc, expected *Place) withPlaceFn { - return func (p *Place) error { - if !assertDeepEquals(fn, p , expected) { + return func(p *Place) error { + if !assertDeepEquals(fn, p, expected) { return fmt.Errorf("not equal") } return nil @@ -69,22 +69,22 @@ func TestOnPlace(t *testing.T) { }{ { name: "single", - args: args{ testPlace, assertPlaceWithTesting }, + args: args{testPlace, assertPlaceWithTesting}, wantErr: false, }, { name: "single fails", - args: args{ Place{ID: "https://not-equals"}, assertPlaceWithTesting }, + args: args{Place{ID: "https://not-equals"}, assertPlaceWithTesting}, wantErr: true, }, { name: "collectionOfPlaces", - args: args{ItemCollection{testPlace, testPlace}, assertPlaceWithTesting }, + args: args{ItemCollection{testPlace, testPlace}, assertPlaceWithTesting}, wantErr: false, }, { name: "collectionOfPlaces fails", - args: args{ ItemCollection{testPlace, Place{ID: "https://not-equals"}}, assertPlaceWithTesting }, + args: args{ItemCollection{testPlace, Place{ID: "https://not-equals"}}, assertPlaceWithTesting}, wantErr: true, }, } diff --git a/profile_test.go b/profile_test.go index 2be3889..97ee9d6 100644 --- a/profile_test.go +++ b/profile_test.go @@ -46,8 +46,8 @@ func TestProfile_Clean(t *testing.T) { } func assertProfileWithTesting(fn canErrorFunc, expected *Profile) withProfileFn { - return func (p *Profile) error { - if !assertDeepEquals(fn, p , expected) { + return func(p *Profile) error { + if !assertDeepEquals(fn, p, expected) { return fmt.Errorf("not equal") } return nil diff --git a/question_test.go b/question_test.go index 2d5b8f8..14fc7d8 100644 --- a/question_test.go +++ b/question_test.go @@ -55,7 +55,6 @@ func TestQuestion_GetType(t *testing.T) { } } - func TestToQuestion(t *testing.T) { var it Item act := QuestionNew("test") diff --git a/tombstone_test.go b/tombstone_test.go index b8949a9..19bcd2a 100644 --- a/tombstone_test.go +++ b/tombstone_test.go @@ -37,8 +37,8 @@ func TestTombstone_Clean(t *testing.T) { t.Skipf("TODO") } func assertTombstoneWithTesting(fn canErrorFunc, expected *Tombstone) withTombstoneFn { - return func (p *Tombstone) error { - if !assertDeepEquals(fn, p , expected) { + return func(p *Tombstone) error { + if !assertDeepEquals(fn, p, expected) { return fmt.Errorf("not equal") } return nil