-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclient_test.go
90 lines (88 loc) · 5.62 KB
/
client_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
package dyatl
import (
"strings"
"testing"
)
func TestPreview(t *testing.T) {
c := NewClient()
for link, testCase := range map[string]Preview{
"https://www.youtube.com/watch?v=eLAHSRmFFzE": {
ThumbnailUrl: "https://i.ytimg.com/vi/eLAHSRmFFzE/hqdefault.jpg",
Title: "Noize MC",
YoutubeId: "eLAHSRmFFzE",
},
"https://www.youtube.com/watch?v=Ud3p8p9hqHc": {
ThumbnailUrl: "https://i.ytimg.com/vi/Ud3p8p9hqHc/hqdefault.jpg",
Title: "Коронавирус в Китае:",
YoutubeId: "", // empty for private video because can't be embedded
},
"http://example.com.": {
Title: "Example Domain",
},
"https://vk.com/shantitrash": {
// skip: has different servers for thumbnails
// ThumbnailUrl: "http://sun1-89.userapi.com/impf/c631625/v631625378/401/bXrjmBHZwP8.jpg?size=200x0&quality=96&crop=59,23,527,528&sign=b6e64806e0947daa745c9ed26df5c427&ava=1",
Title: "Шанти-трэш",
},
"https://habr.com/ru/post/354472/": {
ThumbnailUrl: "https://habr.com/share/publication/354472/590e252e0c6748a2c367a8c72a67c422/",
Title: "Бэкап переписки в telegram",
},
// FIXME: moved to js
//"https://yandex.ru/maps/213/moscow/?ll=37.656245%2C55.759324&mode=search&oid=1111668074&ol=biz&sctx=ZAAAAAgCEAAaKAoSCYnQCDauz0JAEabtX1lp4EtAEhIJA137Anqh8j8RmPxP%2Fu4d7D8iBQABAgQFKAAwATi47Z3olunF%20cQBQNUBSAFVzczMPlgAYiRtaWRkbGVfYXNrX2RpcmVjdF9xdWVyeV90eX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2FsL0dlby9Vc2VHZW9UcmF2ZWxSdWxlPTFqAnJ1cAGVAQAAAACdAc3MTD6gAQGoAQC9ASpEmwfCAQvq6oqSBLSz54m4Bg%3D%3D&sll=37.656245%2C55.759324&source=wizbiz_new_map_single&text=copyprint%20%D0%BA%D1%83%D1%80%D1%81%D0%BA%D0%B0%D1%8F&z=14": {
// ThumbnailUrl: "https://avatars.mds.yandex.net/get-altay/910613/2a000001622d8e17052f70e2a85a00c18bfe/L",
// Title: "Copyprint, копировальный центр, Яковоапостольский пер., 17 — Яндекс.Карты",
//},
"http://hidemyname.link/EN8f3g": {
ThumbnailUrl: "https://hidemy.name/media/img/news/evropejskim-chinovnikam-rekomendujut-udalit-whatsapp-i-facebook-messenger.jpg",
Title: "Европейским чиновникам рекомендуют удалить WhatsApp и Facebook Messenger",
},
"https://cl.ly/391E2W3E111s": {
ThumbnailUrl: "https://f.v1.n0.cdn.getcloudapp.com/items/3P0J3Z3y1o380L2l3X36/Image%202016-09-15%20at%2012.02.06%20PM.png",
Title: "Image 2016-09-15 at 12.02.06 PM",
},
"https://meduza.io/shapito/2020/04/22/vsegda-priyatno-posmotret-na-usatyh-loshadey-a-kogda-tak-malo-horoshih-novostey-tem-bolee": {
ThumbnailUrl: "https://meduza.io/imgly/share/1587572704/shapito/2020/04/22/vsegda-priyatno-posmotret-na-usatyh-loshadey-a-kogda-tak-malo-horoshih-novostey-tem-bolee",
Title: "Всегда приятно посмотреть на усатых лошадей",
},
"https://zoom.us/j/97953527417?pwd=ZU9YaVFTNjBhb0t3dDh4bFJoZlVKQT09": {
Title: "Join our Cloud HD Video Meeting",
},
//"https://m.facebook.com/id77777/posts/10154846872521076": {
// //Title: "Telegram собрался на ICO. В последнее время я несколько раз слышал от участников рынка слухи о том, что Telegram план...",
// Title: "Для просмотра нужно войти или зарегистрироваться",
//},
"https://www.facebook.com/groups/AliensAnonymous/permalink/2849150112008665": {
Title: "Facebook",
},
"https://github.com/meetecho/janus-gateway": {
ThumbnailUrl: "https://repository-images.githubusercontent.com/16734696/cb265c80-651c-11ea-9c93-c54a2d2284e7",
Title: "GitHub - meetecho/janus-gateway: Janus WebRTC Server",
//Title: "meetecho/janus-gateway",
},
// FIXME: stopped after 10 redirects
//"https://developer.android.com/guide/topics/connectivity/telecom": {
// Title: "Telecom framework overview |",
//},
"https://habr.com/ru/": {
ThumbnailUrl: "https://habr.com/img/habr_en.png",
Title: "Все публикации подряд / Хабр",
},
} {
t.Run(link, func(t *testing.T) {
result, err := c.Preview(link)
if err != nil {
t.Fatal(err)
}
if testCase.ThumbnailUrl != "" && result.ThumbnailUrl != testCase.ThumbnailUrl {
t.Errorf("invalid ThumbnailUrl:\nwant: `%s`\ngot: `%s`", testCase.ThumbnailUrl, result.ThumbnailUrl)
}
if !strings.HasPrefix(result.Title, testCase.Title) {
t.Errorf("invalid Title:\nwant: `%s`\ngot: `%s`", testCase.Title, result.Title)
}
if result.YoutubeId != testCase.YoutubeId {
t.Errorf("invalid YoutubeId:\nwant: `%s`\ngot: `%s`", testCase.YoutubeId, result.YoutubeId)
}
})
}
}