mirror of
https://github.com/miniflux/v2.git
synced 2025-08-01 17:38:37 +00:00
test(rewrite): add unit test for referer rewrite function
This commit is contained in:
parent
e6185b1393
commit
113abeea59
1 changed files with 67 additions and 0 deletions
67
internal/reader/rewrite/referer_override_test.go
Normal file
67
internal/reader/rewrite/referer_override_test.go
Normal file
|
@ -0,0 +1,67 @@
|
|||
// SPDX-FileCopyrightText: Copyright The Miniflux Authors. All rights reserved.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package rewrite // import "miniflux.app/v2/internal/reader/rewrite"
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestGetRefererForURL(t *testing.T) {
|
||||
testCases := []struct {
|
||||
name string
|
||||
url string
|
||||
expected string
|
||||
}{
|
||||
{
|
||||
name: "Weibo Image URL",
|
||||
url: "https://wx1.sinaimg.cn/large/example.jpg",
|
||||
expected: "https://weibo.com",
|
||||
},
|
||||
{
|
||||
name: "Pixiv Image URL",
|
||||
url: "https://i.pximg.net/img-master/example.jpg",
|
||||
expected: "https://www.pixiv.net",
|
||||
},
|
||||
{
|
||||
name: "SSPai CDN URL",
|
||||
url: "https://cdnfile.sspai.com/example.png",
|
||||
expected: "https://sspai.com",
|
||||
},
|
||||
{
|
||||
name: "Instagram CDN URL",
|
||||
url: "https://scontent-sjc3-1.cdninstagram.com/example.jpg",
|
||||
expected: "https://www.instagram.com",
|
||||
},
|
||||
{
|
||||
name: "Piokok URL",
|
||||
url: "https://sp1.piokok.com/example.jpg",
|
||||
expected: "https://sp1.piokok.com",
|
||||
},
|
||||
{
|
||||
name: "Weibo Video URL",
|
||||
url: "https://f.video.weibocdn.com/example.mp4",
|
||||
expected: "https://weibo.com",
|
||||
},
|
||||
{
|
||||
name: "HelloGithub Image URL",
|
||||
url: "https://img.hellogithub.com/example.png",
|
||||
expected: "https://hellogithub.com",
|
||||
},
|
||||
{
|
||||
name: "Non-matching URL",
|
||||
url: "https://example.com/image.jpg",
|
||||
expected: "",
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range testCases {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
result := GetRefererForURL(tc.url)
|
||||
if result != tc.expected {
|
||||
t.Errorf("GetRefererForURL(%s): expected %s, got %s",
|
||||
tc.url, tc.expected, result)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue