11 1d5ddf5d 2024-02-20 o func TestDecode(t *testing.T) {
12 77918b00 2024-03-07 o f, err := os.Open("testdata/announce1.json")
13 77918b00 2024-03-07 o if err != nil {
16 77918b00 2024-03-07 o defer f.Close()
17 77918b00 2024-03-07 o a, err := Decode(f)
18 77918b00 2024-03-07 o if err != nil {
19 77918b00 2024-03-07 o t.Fatal("decode activity", err)
21 77918b00 2024-03-07 o want := "https://lemmy.sdf.org/activities/like/b5bd1577-9677-4130-8312-cd2e2fd4ea44"
22 77918b00 2024-03-07 o inner, err := a.Unwrap(nil)
23 77918b00 2024-03-07 o if err != nil {
24 77918b00 2024-03-07 o t.Fatal("unwrap activity:", err)
26 77918b00 2024-03-07 o if inner.ID != want {
27 77918b00 2024-03-07 o t.Errorf("wanted wrapped activity id %s, got %s", want, inner.ID)
31 1738cb32 2024-03-12 o func TestTag(t *testing.T) {
32 1738cb32 2024-03-12 o tests := []struct {
36 1738cb32 2024-03-12 o {"testdata/note/akkoma.json", "@otl@apubtest2.srcbeat.com"},
37 1738cb32 2024-03-12 o {"testdata/note/lemmy.json", "@Feathercrown@lemmy.world"},
38 1738cb32 2024-03-12 o {"testdata/note/mastodon.json", "@selfhosted@lemmy.world"},
40 1738cb32 2024-03-12 o for _, tt := range tests {
41 1738cb32 2024-03-12 o f, err := os.Open(tt.Name)
42 1738cb32 2024-03-12 o if err != nil {
46 1738cb32 2024-03-12 o defer f.Close()
47 1738cb32 2024-03-12 o a, err := Decode(f)
48 1738cb32 2024-03-12 o if err != nil {
49 1738cb32 2024-03-12 o t.Errorf("%s: decode: %v", tt.Name, err)
52 1738cb32 2024-03-12 o if len(a.Tag) == 0 {
53 1738cb32 2024-03-12 o t.Errorf("%s: no tags", tt.Name)
57 1738cb32 2024-03-12 o for _, tag := range a.Tag {
58 1738cb32 2024-03-12 o if tag.Name == tt.Mention {
63 1738cb32 2024-03-12 o t.Errorf("%s: did not find mention %s", tt.Name, tt.Mention)
68 8403ab16 2024-03-21 o func TestInboxes(t *testing.T) {
69 8403ab16 2024-03-21 o want := []string{
70 8403ab16 2024-03-21 o "https://apubtest2.srcbeat.com/otl/inbox",
71 8403ab16 2024-03-21 o "https://hachyderm.io/inbox",
72 8403ab16 2024-03-21 o "https://lemmy.world/inbox",
73 8403ab16 2024-03-21 o "https://social.harpia.red/inbox",
76 8403ab16 2024-03-21 o root := "testdata/actor"
77 8403ab16 2024-03-21 o dirent, err := os.ReadDir("testdata/actor")
78 8403ab16 2024-03-21 o if err != nil {
81 8403ab16 2024-03-21 o actors := make([]Actor, len(dirent))
82 8403ab16 2024-03-21 o for i, ent := range dirent {
83 8403ab16 2024-03-21 o f, err := os.Open(path.Join(root, ent.Name()))
84 8403ab16 2024-03-21 o if err != nil {
87 8403ab16 2024-03-21 o defer f.Close()
88 8403ab16 2024-03-21 o a, err := DecodeActor(f)
89 8403ab16 2024-03-21 o if err != nil {
94 8403ab16 2024-03-21 o got := Inboxes(actors)
95 8403ab16 2024-03-21 o sort.Strings(got)
96 8403ab16 2024-03-21 o if !reflect.DeepEqual(want, got) {
97 8403ab16 2024-03-21 o t.Errorf("unexpected inbox slice of multiple actors, want %s got %s", want, got)