1package blob23import (4 "reflect"5 "testing"67 "github.com/FelineStateMachine/tinyrelay/internal/event"8)910func 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}2829func 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}