8 1d5ddf5d 2024-02-20 o func TestDecode(t *testing.T) {
9 77918b00 2024-03-07 o f, err := os.Open("testdata/announce1.json")
10 77918b00 2024-03-07 o if err != nil {
13 77918b00 2024-03-07 o defer f.Close()
14 77918b00 2024-03-07 o a, err := Decode(f)
15 77918b00 2024-03-07 o if err != nil {
16 77918b00 2024-03-07 o t.Fatal("decode activity", err)
18 77918b00 2024-03-07 o want := "https://lemmy.sdf.org/activities/like/b5bd1577-9677-4130-8312-cd2e2fd4ea44"
19 77918b00 2024-03-07 o inner, err := a.Unwrap(nil)
20 77918b00 2024-03-07 o if err != nil {
21 77918b00 2024-03-07 o t.Fatal("unwrap activity:", err)
23 77918b00 2024-03-07 o if inner.ID != want {
24 77918b00 2024-03-07 o t.Errorf("wanted wrapped activity id %s, got %s", want, inner.ID)
28 1738cb32 2024-03-12 o func TestTag(t *testing.T) {
29 1738cb32 2024-03-12 o tests := []struct {
33 1738cb32 2024-03-12 o {"testdata/note/akkoma.json", "@otl@apubtest2.srcbeat.com"},
34 1738cb32 2024-03-12 o {"testdata/note/lemmy.json", "@Feathercrown@lemmy.world"},
35 1738cb32 2024-03-12 o {"testdata/note/mastodon.json", "@selfhosted@lemmy.world"},
37 1738cb32 2024-03-12 o for _, tt := range tests {
38 1738cb32 2024-03-12 o f, err := os.Open(tt.Name)
39 1738cb32 2024-03-12 o if err != nil {
43 1738cb32 2024-03-12 o defer f.Close()
44 1738cb32 2024-03-12 o a, err := Decode(f)
45 1738cb32 2024-03-12 o if err != nil {
46 1738cb32 2024-03-12 o t.Errorf("%s: decode: %v", tt.Name, err)
49 1738cb32 2024-03-12 o if len(a.Tag) == 0 {
50 1738cb32 2024-03-12 o t.Errorf("%s: no tags", tt.Name)
54 1738cb32 2024-03-12 o for _, tag := range a.Tag {
55 1738cb32 2024-03-12 o if tag.Name == tt.Mention {
60 1738cb32 2024-03-12 o t.Errorf("%s: did not find mention %s", tt.Name, tt.Mention)