|
| 1 | +package oembed |
| 2 | + |
| 3 | +import ( |
| 4 | + "testing" |
| 5 | + |
| 6 | + "github.com/stretchr/testify/assert" |
| 7 | +) |
| 8 | + |
| 9 | +func TestFetchEmbed(t *testing.T) { |
| 10 | + assert := assert.New(t) |
| 11 | + t.Run("valid", func(t *testing.T) { |
| 12 | + resp, err := fetchEmbed( |
| 13 | + "https://www.youtube.com/watch?v=8jPQjjsBbIc", |
| 14 | + makeCandidate(Provider{ |
| 15 | + Name: "YouTube", |
| 16 | + URL: "https://www.youtube.com/", |
| 17 | + Endpoints: []Endpoint{Endpoint{ |
| 18 | + Schemes: []string{ |
| 19 | + "https://*.youtube.com/watch*", |
| 20 | + "https://*.youtube.com/v/*\"", |
| 21 | + "https://youtu.be/*", |
| 22 | + }, |
| 23 | + URL: "https://www.youtube.com/oembed", |
| 24 | + Discovery: true, |
| 25 | + }}, |
| 26 | + }), |
| 27 | + &Params{ |
| 28 | + MaxWidth: 250, |
| 29 | + MaxHeight: 250, |
| 30 | + }, |
| 31 | + ) |
| 32 | + assert.NoError(err) |
| 33 | + assert.NotNil(resp) |
| 34 | + }) |
| 35 | + t.Run("invalid", func(t *testing.T) { |
| 36 | + for _, url := range []string{ |
| 37 | + "", |
| 38 | + "htt:/abc.com/failed-none-sense", |
| 39 | + "https://abc.com/failed-none-sense", |
| 40 | + "http://badcom/146753785", |
| 41 | + "https://674458092126388225", |
| 42 | + "http://www.ted.com/talks/something-does-not-exist", |
| 43 | + "https://soundcloud^(*%%$%^$$%$$*&(&)())", |
| 44 | + "https://www.flickr.com/services/oembed/?url=http%3A//www.flickr.com/photos/bees/23416sa/", |
| 45 | + } { |
| 46 | + url := url |
| 47 | + t.Run(url, func(t *testing.T) { |
| 48 | + c := findProvider(url) |
| 49 | + if c == nil { |
| 50 | + c = new(providerCandidate) |
| 51 | + } |
| 52 | + |
| 53 | + _, err := fetchEmbed(url, *c, nil) |
| 54 | + assert.Error(err) |
| 55 | + }) |
| 56 | + } |
| 57 | + }) |
| 58 | +} |
0 commit comments