This repository has no description
0

Configure Feed

Select the types of activity you want to include in your feed.

core / appview / pages / markup / blob_test.go
1.9 kB 90 lines
1package markup 2 3import ( 4 "testing" 5 6 "github.com/bluesky-social/indigo/atproto/syntax" 7) 8 9func TestParseBlobURI(t *testing.T) { 10 tests := []struct { 11 name string 12 src string 13 wantDid syntax.DID 14 wantCid syntax.CID 15 wantOk bool 16 }{ 17 { 18 name: "valid plc", 19 src: "blob+at://did:plc:abc123/bafyreiabc", 20 wantDid: "did:plc:abc123", 21 wantCid: "bafyreiabc", 22 wantOk: true, 23 }, 24 { 25 name: "valid web", 26 src: "blob+at://did:web:example.com/bafyreiabc", 27 wantDid: "did:web:example.com", 28 wantCid: "bafyreiabc", 29 wantOk: true, 30 }, 31 { 32 name: "missing cid", 33 src: "blob+at://did:plc:abc123", 34 wantOk: false, 35 }, 36 { 37 name: "empty cid", 38 src: "blob+at://did:plc:abc123/", 39 wantOk: false, 40 }, 41 { 42 name: "empty did", 43 src: "blob+at:///bafyreiabc", 44 wantOk: false, 45 }, 46 { 47 name: "wrong scheme", 48 src: "https://example.com/image.png", 49 wantOk: false, 50 }, 51 { 52 name: "bare at scheme", 53 src: "at://did:plc:abc123/bafyreiabc", 54 wantOk: false, 55 }, 56 { 57 name: "empty", 58 src: "", 59 wantOk: false, 60 }, 61 } 62 63 for _, tt := range tests { 64 t.Run(tt.name, func(t *testing.T) { 65 did, cid, ok := parseBlobURI(tt.src) 66 if ok != tt.wantOk { 67 t.Fatalf("parseBlobURI(%q) ok = %v, want %v", tt.src, ok, tt.wantOk) 68 } 69 if !tt.wantOk { 70 return 71 } 72 if did != tt.wantDid || cid != tt.wantCid { 73 t.Fatalf("parseBlobURI(%q) = (%q, %q), want (%q, %q)", tt.src, did, cid, tt.wantDid, tt.wantCid) 74 } 75 }) 76 } 77} 78 79// A nil resolver must never panic and must signal "not rewritten". 80func TestBlobToGetBlobURLNilResolver(t *testing.T) { 81 rctx := &RenderContext{} 82 src := "blob+at://did:plc:abc123/bafyreiabc" 83 got, ok := rctx.blobToGetBlobURL(src) 84 if ok { 85 t.Fatalf("expected ok=false with nil resolver") 86 } 87 if got != src { 88 t.Fatalf("expected src returned unchanged, got %q", got) 89 } 90}