A community based topic aggregation platform built on atproto
1package unfurl 2 3import ( 4 "testing" 5 6 "github.com/stretchr/testify/assert" 7) 8 9func TestNormalizeURL(t *testing.T) { 10 tests := []struct { 11 name string 12 input string 13 expected string 14 }{ 15 { 16 name: "protocol-relative URL", 17 input: "//cdn.example.com/image.jpg", 18 expected: "https://cdn.example.com/image.jpg", 19 }, 20 { 21 name: "https URL unchanged", 22 input: "https://example.com/image.jpg", 23 expected: "https://example.com/image.jpg", 24 }, 25 { 26 name: "http URL unchanged", 27 input: "http://example.com/image.jpg", 28 expected: "http://example.com/image.jpg", 29 }, 30 { 31 name: "empty string", 32 input: "", 33 expected: "", 34 }, 35 { 36 name: "protocol-relative with query params", 37 input: "//cdn.example.com/image.jpg?width=500&height=300", 38 expected: "https://cdn.example.com/image.jpg?width=500&height=300", 39 }, 40 { 41 name: "real Streamable URL", 42 input: "//cdn-cf-east.streamable.com/image/7kpdft.jpg?Expires=1762932720", 43 expected: "https://cdn-cf-east.streamable.com/image/7kpdft.jpg?Expires=1762932720", 44 }, 45 } 46 47 for _, tt := range tests { 48 t.Run(tt.name, func(t *testing.T) { 49 result := normalizeURL(tt.input) 50 assert.Equal(t, tt.expected, result) 51 }) 52 } 53}