-
Notifications
You must be signed in to change notification settings - Fork 1
/
eztv_test.go
159 lines (139 loc) · 6.23 KB
/
eztv_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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
package eztv
import (
"fmt"
"net/http"
"net/http/httptest"
"reflect"
"testing"
"time"
)
// TestShowNotFound tests the ErrShowNotFound error
func TestShowNotFound(t *testing.T) {
var requestURI string
rawHTMLResponse := `{ "torrents_count": 280450, "limit": 30, "page": 1, "torrents": [] }`
// Fake server with a fake answer
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
requestURI = r.RequestURI
fmt.Fprintln(w, rawHTMLResponse)
}))
defer ts.Close()
endpoint = ts.URL
_, err := GetShowTorrents("fakeID")
if err == nil {
t.Fatalf("got no error, expected %q", ErrShowNotFound)
}
expectedRequestURI := "/api/get-torrents?imdb_id=fakeID&limit=100&page=1"
if requestURI != expectedRequestURI {
t.Fatalf("expected URL %q, got %q", expectedRequestURI, requestURI)
}
if err != ErrShowNotFound {
t.Fatalf("expected %q, got %q", ErrShowNotFound, err)
}
}
// TestBadGetShowDetails tests GetShowTorrents with missing arguments
func TestBadGetShowDetails(t *testing.T) {
_, err := GetShowTorrents("")
if err == nil {
t.Fatalf("should raise an error with missing argument")
}
if err != ErrMissingArgument {
t.Errorf("should raise an error ErrMissingArgument")
}
}
// TestGetShowTorrents tests GetShowTorrents
func TestGetShowTorrents(t *testing.T) {
// Fake server with a fake answer
var requestURI string
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
requestURI = r.RequestURI
fmt.Fprintln(w, rawResponseGetTorrents)
}))
defer ts.Close()
endpoint = ts.URL
s, err := GetShowTorrents("tt0383795")
if err != nil {
t.Fatalf("error while getting show torrents %+v", err)
}
expectedRequestURI := "/api/get-torrents?imdb_id=0383795&limit=100&page=1"
if requestURI != expectedRequestURI {
t.Fatalf("expected URL %q, got %q", expectedRequestURI, requestURI)
}
if reflect.DeepEqual(s, expectedTorrents) == false {
t.Errorf("invalid torrent, expecting:\n %+v\nand got:\n%+v", expectedTorrents[0], s[0])
}
}
// TestGetEpisodeTorrents tests GetEpisodeTorrents
func TestGetEpisodeTorrents(t *testing.T) {
// Fake server with a fake answer
var requestURI string
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
requestURI = r.RequestURI
fmt.Fprintln(w, rawResponseGetTorrents)
}))
defer ts.Close()
endpoint = ts.URL
e, err := GetEpisodeTorrents("tt2085059", 1, 1)
if err == nil {
t.Errorf("no errors while getting unknown show details %+v", err)
}
if e != nil {
t.Error("episode should be nil", e)
}
if err != ErrEpisodeNotFound {
t.Error("error should be ErrEpisodeNotFound", err)
}
e, err = GetEpisodeTorrents("tt0383795", 1, 10)
if err != nil {
t.Errorf("error while getting episode torrents %+v", err)
}
expectedRequestURI := "/api/get-torrents?imdb_id=0383795&limit=100&page=1"
if requestURI != expectedRequestURI {
t.Fatalf("expected URL %q, got %q", expectedRequestURI, requestURI)
}
if reflect.DeepEqual(e, expectedTorrents) == false {
t.Errorf("invalid torrent, expecting:\n%+v\nand got:\n%+v", expectedTorrents, e)
}
}
// TestGetTorrents tests GetTorrents
func TestGetTorrents(t *testing.T) {
// Fake server with a fake answer
var requestURI string
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
requestURI = r.RequestURI
fmt.Fprintln(w, rawResponseGetTorrents)
}))
defer ts.Close()
endpoint = ts.URL
e, err := GetTorrents(10, 1)
if err != nil {
t.Errorf("error while getting torrents %+v", err)
}
expectedRequestURI := "/api/get-torrents?limit=10&page=1"
if requestURI != expectedRequestURI {
t.Fatalf("expected URL %q, got %q", expectedRequestURI, requestURI)
}
if reflect.DeepEqual(e, expectedTorrents) == false {
t.Errorf("invalid torrent, expecting:\n%+v\nand got:\n%+v", expectedTorrents, e)
}
}
var rawResponseGetTorrents = `{ "torrents_count": 280450, "limit": 30, "page": 1, "imdb_id": "0383795", "torrents": [{ "id": 1443504, "hash": "033712dc2a9c6b23edbcbea737ee6ecf02619c2e", "filename": "The.Joy.of.Painting.S01E10.INTERNAL.480p.x264-mSD[eztv].mkv", "episode_url": "https://eztv.io/ep/1443504/the-joy-of-painting-s01e10-internal-480p-x264-msd/", "torrent_url": "https://zoink.ch/torrent/The.Joy.of.Painting.S01E10.INTERNAL.480p.x264-mSD[eztv].mkv.torrent", "magnet_url": "magnet:?xt=urn:btih:033712dc2a9c6b23edbcbea737ee6ecf02619c2e&dn=The.Joy.of.Painting.S01E10.INTERNAL.480p.x264-mSD%5Beztv%5D&tr=udp://tracker.coppersurfer.tk:80&tr=udp://glotorrents.pw:6969/announce&tr=udp://tracker.leechers-paradise.org:6969&tr=udp://tracker.opentrackr.org:1337/announce&tr=udp://exodus.desync.com:6969", "title": "The Joy of Painting S01E10 INTERNAL 480p x264-mSD EZTV", "imdb_id": "0383795", "season": "1", "episode": "10", "small_screenshot": "//ezimg.ch/thumbs/the-joy-of-painting-s01e10-internal-480p-x264-msd-small.jpg", "large_screenshot": "//ezimg.ch/thumbs/the-joy-of-painting-s01e10-internal-480p-x264-msd-large.jpg", "seeds": 64, "peers": 0,"date_released_unix": 1588784249, "size_bytes": "86643580"}]}`
var expectedTorrents = []*EpisodeTorrent{
{
ID: 1443504,
Hash: "033712dc2a9c6b23edbcbea737ee6ecf02619c2e",
Filename: "The.Joy.of.Painting.S01E10.INTERNAL.480p.x264-mSD[eztv].mkv",
EpisodeURL: "https://eztv.io/ep/1443504/the-joy-of-painting-s01e10-internal-480p-x264-msd/",
TorrentURL: "https://zoink.ch/torrent/The.Joy.of.Painting.S01E10.INTERNAL.480p.x264-mSD[eztv].mkv.torrent",
MagnetURL: "magnet:?xt=urn:btih:033712dc2a9c6b23edbcbea737ee6ecf02619c2e&dn=The.Joy.of.Painting.S01E10.INTERNAL.480p.x264-mSD%5Beztv%5D&tr=udp://tracker.coppersurfer.tk:80&tr=udp://glotorrents.pw:6969/announce&tr=udp://tracker.leechers-paradise.org:6969&tr=udp://tracker.opentrackr.org:1337/announce&tr=udp://exodus.desync.com:6969",
Title: "The Joy of Painting S01E10 INTERNAL 480p x264-mSD EZTV",
ImdbID: "tt0383795",
Season: 1,
Episode: 10,
SmallScreenshot: "https://ezimg.ch/thumbs/the-joy-of-painting-s01e10-internal-480p-x264-msd-small.jpg",
LargeScreenshot: "https://ezimg.ch/thumbs/the-joy-of-painting-s01e10-internal-480p-x264-msd-large.jpg",
Seeds: 64,
Peers: 0,
DateReleased: time.Unix(1588784249, 0),
Size: 86643580,
},
}