Fixed linting

This commit is contained in:
Shivek Khurana 2021-02-03 18:55:42 +05:30 committed by Andrea Maria Piana
parent ad6229bc4f
commit 4b5dbc3d52
2 changed files with 10 additions and 11 deletions

View File

@ -179,6 +179,7 @@ func GetGiphyPreviewData(link string) (previewData LinkPreviewData, err error) {
// Giphy has a shortener service called gph.se, the oembed service doesn't work with shortened urls,
// so we need to fetch the long url first
func GetGiphyLongURL(shortURL string) (longURL string, err error) {
// nolint: gosec
res, err := http.Get(shortURL)
if err != nil {
@ -186,22 +187,22 @@ func GetGiphyLongURL(shortURL string) (longURL string, err error) {
}
canonicalURL := res.Request.URL.String()
if (canonicalURL == shortURL) {
if canonicalURL == shortURL {
// no redirect, ie. not a valid url
return longURL, fmt.Errorf("unable to process Giphy's short url at %s", shortURL)
} else {
return canonicalURL, err
}
return canonicalURL, err
}
func GetGiphyShortURLPreviewData (shortURL string) (data LinkPreviewData, err error) {
func GetGiphyShortURLPreviewData(shortURL string) (data LinkPreviewData, err error) {
longURL, err := GetGiphyLongURL(shortURL)
if err != nil {
return data, err
} else {
return GetGiphyPreviewData(longURL)
}
return GetGiphyPreviewData(longURL)
}
func GetTenorOembed(url string) (data TenorOembedData, err error) {

View File

@ -33,7 +33,7 @@ func TestGetLinkPreviewData(t *testing.T) {
}
// split at "." and ignore the first item
func thumbnailUrlWithoutSubdomain(url string) []string {
func thumbnailURLWithoutSubdomain(url string) []string {
return strings.Split(url, ".")[1:]
}
@ -51,18 +51,17 @@ func TestGetGiphyPreviewData(t *testing.T) {
// Giphy oembed returns links to different servers: https://media1.giphy.com, https://media2.giphy.com and so on
// We don't care about the server as long as other parts are equal, so we split at "." and ignore the first item
require.Equal(t, thumbnailUrlWithoutSubdomain(bostonDynamicsEthGifData.ThumbnailURL), thumbnailUrlWithoutSubdomain(previewData.ThumbnailURL))
require.Equal(t, thumbnailURLWithoutSubdomain(bostonDynamicsEthGifData.ThumbnailURL), thumbnailURLWithoutSubdomain(previewData.ThumbnailURL))
invalidGiphyLink := "https://giphy.com/gifs/this-gif-does-not-exist-44444"
_, err = GetGiphyPreviewData(invalidGiphyLink)
require.Error(t, err)
mediaLink := "https://media.giphy.com/media/lcG3qwtTKSNI2i5vst/giphy.gif"
mediaLinkData, _ := GetGiphyPreviewData(mediaLink)
require.Equal(t, thumbnailUrlWithoutSubdomain(mediaLinkData.ThumbnailURL), thumbnailUrlWithoutSubdomain(previewData.ThumbnailURL))
require.Equal(t, thumbnailURLWithoutSubdomain(mediaLinkData.ThumbnailURL), thumbnailURLWithoutSubdomain(previewData.ThumbnailURL))
}
func TestGetGiphyLongURL(t *testing.T) {
@ -79,7 +78,6 @@ func TestGetGiphyLongURL(t *testing.T) {
require.Error(t, err)
}
func TestGetGiphyShortURLPreviewData(t *testing.T) {
shortURL := "https://gph.is/g/aXLyK7P"
previewData, err := GetGiphyShortURLPreviewData(shortURL)