2019-12-03 16:23:59 +00:00
|
|
|
package activitypub
|
2017-09-16 10:31:23 +00:00
|
|
|
|
2018-04-08 22:32:29 +00:00
|
|
|
import (
|
2021-12-30 18:01:15 +00:00
|
|
|
"reflect"
|
2018-04-08 22:32:29 +00:00
|
|
|
"testing"
|
|
|
|
)
|
2017-09-16 10:31:23 +00:00
|
|
|
|
|
|
|
func TestLinkNew(t *testing.T) {
|
2019-12-05 18:02:15 +00:00
|
|
|
var testValue = ID("test")
|
2017-10-02 09:53:09 +00:00
|
|
|
var testType ActivityVocabularyType
|
2017-09-16 10:31:23 +00:00
|
|
|
|
|
|
|
l := LinkNew(testValue, testType)
|
|
|
|
|
2018-06-07 19:25:35 +00:00
|
|
|
if l.ID != testValue {
|
|
|
|
t.Errorf("APObject Id '%v' different than expected '%v'", l.ID, testValue)
|
2017-09-16 10:31:23 +00:00
|
|
|
}
|
|
|
|
if l.Type != LinkType {
|
2017-10-05 10:38:11 +00:00
|
|
|
t.Errorf("APObject Type '%v' different than expected '%v'", l.Type, LinkType)
|
2017-09-16 10:31:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-10-02 09:53:09 +00:00
|
|
|
func TestLink_IsLink(t *testing.T) {
|
|
|
|
l := LinkNew("test", LinkType)
|
|
|
|
if !l.IsLink() {
|
|
|
|
t.Errorf("%#v should be a valid link", l.Type)
|
|
|
|
}
|
|
|
|
m := LinkNew("test", MentionType)
|
|
|
|
if !m.IsLink() {
|
|
|
|
t.Errorf("%#v should be a valid link", m.Type)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestLink_IsObject(t *testing.T) {
|
|
|
|
l := LinkNew("test", LinkType)
|
|
|
|
if l.IsObject() {
|
|
|
|
t.Errorf("%#v should not be a valid object", l.Type)
|
|
|
|
}
|
|
|
|
m := LinkNew("test", MentionType)
|
|
|
|
if m.IsObject() {
|
|
|
|
t.Errorf("%#v should not be a valid object", m.Type)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-10 21:37:06 +00:00
|
|
|
func TestLink_GetID(t *testing.T) {
|
2019-05-05 07:32:45 +00:00
|
|
|
t.Skipf("TODO")
|
2018-11-10 21:37:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestLink_GetLink(t *testing.T) {
|
2019-05-05 07:32:45 +00:00
|
|
|
t.Skipf("TODO")
|
2018-11-10 21:37:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestLink_GetType(t *testing.T) {
|
2019-05-05 07:32:45 +00:00
|
|
|
t.Skipf("TODO")
|
2018-11-10 21:37:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestLink_UnmarshalJSON(t *testing.T) {
|
2019-05-05 07:32:45 +00:00
|
|
|
t.Skipf("TODO")
|
2018-11-10 21:37:06 +00:00
|
|
|
}
|
|
|
|
|
2019-12-03 14:33:20 +00:00
|
|
|
func TestMentionNew(t *testing.T) {
|
2019-05-05 07:32:45 +00:00
|
|
|
t.Skipf("TODO")
|
2018-11-10 21:37:06 +00:00
|
|
|
}
|
|
|
|
|
2019-12-03 14:33:20 +00:00
|
|
|
func TestLink_IsCollection(t *testing.T) {
|
2019-05-05 07:32:45 +00:00
|
|
|
t.Skipf("TODO")
|
2018-11-10 21:37:06 +00:00
|
|
|
}
|
2021-12-30 18:01:15 +00:00
|
|
|
|
|
|
|
func TestLink_GobEncode(t *testing.T) {
|
|
|
|
type fields struct {
|
|
|
|
ID ID
|
|
|
|
Type ActivityVocabularyType
|
|
|
|
Name NaturalLanguageValues
|
|
|
|
Rel IRI
|
|
|
|
MediaType MimeType
|
|
|
|
Height uint
|
|
|
|
Width uint
|
|
|
|
Preview Item
|
|
|
|
Href IRI
|
|
|
|
HrefLang LangRef
|
|
|
|
}
|
|
|
|
tests := []struct {
|
|
|
|
name string
|
|
|
|
fields fields
|
|
|
|
want []byte
|
|
|
|
wantErr bool
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
name: "empty",
|
|
|
|
fields: fields{},
|
|
|
|
want: []byte{},
|
|
|
|
wantErr: false,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
|
|
l := Link{
|
|
|
|
ID: tt.fields.ID,
|
|
|
|
Type: tt.fields.Type,
|
|
|
|
Name: tt.fields.Name,
|
|
|
|
Rel: tt.fields.Rel,
|
|
|
|
MediaType: tt.fields.MediaType,
|
|
|
|
Height: tt.fields.Height,
|
|
|
|
Width: tt.fields.Width,
|
|
|
|
Preview: tt.fields.Preview,
|
|
|
|
Href: tt.fields.Href,
|
|
|
|
HrefLang: tt.fields.HrefLang,
|
|
|
|
}
|
|
|
|
got, err := l.GobEncode()
|
|
|
|
if (err != nil) != tt.wantErr {
|
|
|
|
t.Errorf("GobEncode() error = %v, wantErr %v", err, tt.wantErr)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if !reflect.DeepEqual(got, tt.want) {
|
|
|
|
t.Errorf("GobEncode() got = %v, want %v", got, tt.want)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestLink_GobDecode(t *testing.T) {
|
|
|
|
type fields struct {
|
|
|
|
ID ID
|
|
|
|
Type ActivityVocabularyType
|
|
|
|
Name NaturalLanguageValues
|
|
|
|
Rel IRI
|
|
|
|
MediaType MimeType
|
|
|
|
Height uint
|
|
|
|
Width uint
|
|
|
|
Preview Item
|
|
|
|
Href IRI
|
|
|
|
HrefLang LangRef
|
|
|
|
}
|
|
|
|
tests := []struct {
|
|
|
|
name string
|
|
|
|
fields fields
|
|
|
|
data []byte
|
|
|
|
wantErr bool
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
name: "empty",
|
|
|
|
fields: fields{},
|
|
|
|
data: []byte{},
|
|
|
|
wantErr: false,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
|
|
l := &Link{
|
|
|
|
ID: tt.fields.ID,
|
|
|
|
Type: tt.fields.Type,
|
|
|
|
Name: tt.fields.Name,
|
|
|
|
Rel: tt.fields.Rel,
|
|
|
|
MediaType: tt.fields.MediaType,
|
|
|
|
Height: tt.fields.Height,
|
|
|
|
Width: tt.fields.Width,
|
|
|
|
Preview: tt.fields.Preview,
|
|
|
|
Href: tt.fields.Href,
|
|
|
|
HrefLang: tt.fields.HrefLang,
|
|
|
|
}
|
|
|
|
if err := l.GobDecode(tt.data); (err != nil) != tt.wantErr {
|
|
|
|
t.Errorf("GobDecode() error = %v, wantErr %v", err, tt.wantErr)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|