Blob


1 package apub
3 import (
4 "os"
5 "testing"
6 )
8 func TestDecode(t *testing.T) {
9 f, err := os.Open("testdata/announce1.json")
10 if err != nil {
11 t.Fatal(err)
12 }
13 defer f.Close()
14 a, err := Decode(f)
15 if err != nil {
16 t.Fatal("decode activity", err)
17 }
18 want := "https://lemmy.sdf.org/activities/like/b5bd1577-9677-4130-8312-cd2e2fd4ea44"
19 inner, err := a.Unwrap(nil)
20 if err != nil {
21 t.Fatal("unwrap activity:", err)
22 }
23 if inner.ID != want {
24 t.Errorf("wanted wrapped activity id %s, got %s", want, inner.ID)
25 }
26 }
28 func TestTag(t *testing.T) {
29 tests := []struct {
30 Name string
31 Mention string
32 }{
33 {"testdata/note/akkoma.json", "@otl@apubtest2.srcbeat.com"},
34 {"testdata/note/lemmy.json", "@Feathercrown@lemmy.world"},
35 {"testdata/note/mastodon.json", "@selfhosted@lemmy.world"},
36 }
37 for _, tt := range tests {
38 f, err := os.Open(tt.Name)
39 if err != nil {
40 t.Error(err)
41 continue
42 }
43 defer f.Close()
44 a, err := Decode(f)
45 if err != nil {
46 t.Errorf("%s: decode: %v", tt.Name, err)
47 continue
48 }
49 if len(a.Tag) == 0 {
50 t.Errorf("%s: no tags", tt.Name)
51 continue
52 }
53 var found bool
54 for _, tag := range a.Tag {
55 if tag.Name == tt.Mention {
56 found = true
57 }
58 }
59 if !found {
60 t.Errorf("%s: did not find mention %s", tt.Name, tt.Mention)
61 }
62 }
63 }