mirror of
https://github.com/mattermost/mattermost.git
synced 2026-04-15 22:12:19 -04:00
* Split up handling of permalinks and other links in getLinkMetadata * MM-60351 Use oEmbed for YouTube links * Explicitly request json from the oEmbed provider * Fix linter * Fix type of CacheAge field * Address feedback
63 lines
1.6 KiB
Go
63 lines
1.6 KiB
Go
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
|
// See LICENSE.txt for license information.
|
|
|
|
package oembed
|
|
|
|
import (
|
|
"slices"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestFindEndpointForURL(t *testing.T) {
|
|
youtubeProvider := providers[slices.IndexFunc(providers, func(provider *ProviderEndpoint) bool {
|
|
return provider.URL == "https://www.youtube.com/oembed"
|
|
})]
|
|
|
|
for _, testCase := range []struct {
|
|
Name string
|
|
Input string
|
|
Expected *ProviderEndpoint
|
|
}{
|
|
{
|
|
Name: "random URL",
|
|
Input: "https://example.com/some/random.url",
|
|
Expected: nil,
|
|
},
|
|
{
|
|
Name: "YouTube home page",
|
|
Input: "https://www.youtube.com",
|
|
Expected: nil,
|
|
},
|
|
{
|
|
Name: "YouTube video",
|
|
Input: "https://www.youtube.com/watch?v=szfZfQFUSnU",
|
|
Expected: youtubeProvider,
|
|
},
|
|
{
|
|
Name: "YouTube video with short link and tracking information",
|
|
Input: "https://youtu.be/Qq3zukqBFqQ?si=iK_TPT20H30mH90G",
|
|
Expected: youtubeProvider,
|
|
},
|
|
{
|
|
Name: "YouTube video with playlist",
|
|
Input: "https://www.youtube.com/watch?v=Qq3zukqBFqQ&list=PL-jqvaPsjQpMqnRgFEw_3fuGQbcVDTpaM",
|
|
Expected: youtubeProvider,
|
|
},
|
|
{
|
|
Name: "YouTube playlist",
|
|
Input: "https://www.youtube.com/playlist?list=PL-jqvaPsjQpMqnRgFEw_3fuGQbcVDTpaM",
|
|
Expected: youtubeProvider,
|
|
},
|
|
{
|
|
Name: "YouTube channel",
|
|
Input: "https://www.youtube.com/@MattermostHQ",
|
|
Expected: nil,
|
|
},
|
|
} {
|
|
t.Run(testCase.Name, func(t *testing.T) {
|
|
assert.Equal(t, testCase.Expected, FindEndpointForURL(testCase.Input))
|
|
})
|
|
}
|
|
}
|