tinyrelayfile
tinyrelay/internal/blob/blossom_test.go/

internal/blob/blossom_test.go raw
1package blob
2
3import (
4 "reflect"
5 "testing"
6
7 "github.com/FelineStateMachine/tinyrelay/internal/event"
8)
9
10func TestBlossomURIAndFallbacks(t *testing.T) {
11 hash := "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"
12 author := "abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789"
13 u, err := ParseBlossomURI("BLOSSOM:" + hash + ".png?xs=cdn.example&xs=https%3A%2F%2Fb.example&as=" + author + "&as=" + hash + "&sz=42")
14 if err != nil {
15 t.Fatal(err)
16 }
17 if u.Hash != hash || u.Extension != "png" || u.Size != 42 || len(u.Servers) != 2 || len(u.Authors) != 2 {
18 t.Fatalf("parsed URI = %#v", u)
19 }
20 if got := BlobHashFromURL("https://broken/" + hash + ".png"); got != hash {
21 t.Fatalf("hash from URL = %q", got)
22 }
23 want := []string{"https://cdn.example/" + hash + ".png", "http://cdn.example/" + hash + ".png", "https://b.example/" + hash + ".png"}
24 if got := FallbackURLs(u.Servers, hash, "png"); !reflect.DeepEqual(got, want) {
25 t.Fatalf("fallback URLs = %#v", got)
26 }
27}
28
29func TestBlossomServerListPreservesOrder(t *testing.T) {
30 hashless := event.Event{Kind: 10063, Tags: [][]string{{"server", "https://a.example/"}, {"server", "https://b.example"}, {"server", "https://a.example"}}}
31 got, err := BlossomServerList(hashless)
32 if err != nil {
33 t.Fatal(err)
34 }
35 want := []string{"https://a.example", "https://b.example"}
36 if !reflect.DeepEqual(got, want) {
37 t.Fatalf("servers = %#v", got)
38 }
39}

About

ownerc01503e8035f
visibilitypublic
headd730679639bf

Maintainers

  • c01503e8035f owner
  • ba1b5beed5b5 agent hermes

Clone

  • https://012.run/npub1cq2s86qrtadf36eqq3epm38wmhdynrrcwxf84eldk3f94dkv7ttsrulrz5/tinyrelay.git

Refs